-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: Preparing for 0.8.39 release allow override of options.display for facebook auth correct display option for facebook auth minor Fix broken Hull.login without redirect Stray Debugger. Different-sized popups for Facebook Support redirect style Logins Conflicts: bower.json package.json
- Loading branch information
Showing
5 changed files
with
158 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,29 +36,71 @@ define ['underscore', '../utils/promises', '../utils/version'], (_, promises, ve | |
signup = (user) -> | ||
apiFn('users', 'post', user).then emailLoginComplete, loginFailed | ||
|
||
postForm = (path, method='post', params={}) -> | ||
form = document.createElement("form") | ||
form.setAttribute("method", method) | ||
form.setAttribute("action", path) | ||
|
||
for key of params | ||
if params.hasOwnProperty key | ||
hiddenField = document.createElement("input") | ||
hiddenField.setAttribute("type", "hidden") | ||
hiddenField.setAttribute("name", key) | ||
hiddenField.setAttribute("value", params[key]) | ||
form.appendChild(hiddenField) | ||
document.body.appendChild(form) | ||
form.submit() | ||
|
||
login = (params, options={}, callback) -> | ||
refresh = -> | ||
apiFn.clearToken() | ||
apiFn('me') | ||
|
||
# Legacy Format. | ||
if _.isString(params) | ||
if _.isString(options) | ||
# Hull.login('[email protected]','password') | ||
options = {login:params, password:options} | ||
else | ||
# Hull.login('facebook','opts') | ||
options.provider = params | ||
else | ||
# We only use 1 hash for the new setup | ||
options = params | ||
|
||
login = (loginOrProvider, optionsOrPassword, callback) -> | ||
throw new TypeError("'loginOrProvider' must be a String") unless _.isString(loginOrProvider) | ||
|
||
if _.isString(optionsOrPassword) | ||
promise = apiFn('users/login', 'post', { login: loginOrProvider, password: optionsOrPassword }).then -> | ||
apiFn.clearToken() | ||
apiFn('me') | ||
evtPromise = promise.then emailLoginComplete, loginFailed | ||
# Set defaults for Redirect to current page if redirecting. | ||
options.redirect_url = options.redirect_url || window.location.href if options.strategy=='redirect' | ||
|
||
# New Format: | ||
if options.provider? | ||
# Social Login | ||
# Hull.login({provider:'facebook', strategy:'redirect|popup', redirect:'...'}) | ||
promise = loginWithProvider(options).then(refresh) | ||
evtPromise = promise.then _.bind(loginComplete, undefined, params), loginFailed | ||
else | ||
promise = loginWithProvider(loginOrProvider, optionsOrPassword).then -> | ||
apiFn.clearToken() | ||
apiFn('me') | ||
evtPromise = promise.then _.bind(loginComplete, undefined, loginOrProvider), loginFailed | ||
# UserName+Password | ||
# Hull.login({login:'[email protected]', password:'passwd', strategy:'redirect|popup', redirect:'...'}) | ||
|
||
throw new Error('Seems like something is wrong in your Hull.login() call, We need a login and password fields to login. Read up here: http://www.hull.io/docs/references/hull_js/#user-signup-and-login') unless options.login? and options.password? | ||
|
||
# Early return since we're leaving the page. | ||
if options.strategy=='redirect' | ||
return postForm(config.orgUrl+'/api/v1/users/login', 'post', options) | ||
|
||
promise = apiFn('users/login', 'post', _.pick(options, 'login', 'password')).then(refresh) | ||
evtPromise = promise.then emailLoginComplete, loginFailed | ||
|
||
evtPromise.then(callback) if _.isFunction(callback) | ||
|
||
promise | ||
|
||
loginWithProvider = (providerName, opts)-> | ||
loginWithProvider = (options)-> | ||
return module.isAuthenticating() if module.isAuthenticating() | ||
|
||
providerName = providerName.toLowerCase() | ||
providerName = options.provider.toLowerCase() | ||
delete options.provider | ||
|
||
authenticating = promises.deferred() | ||
unless ~(_.indexOf(authServices, providerName )) | ||
authenticating.reject | ||
|
@@ -68,8 +110,18 @@ define ['underscore', '../utils/promises', '../utils/version'], (_, promises, ve | |
|
||
authenticating.providerName = providerName | ||
|
||
authUrl = module.authUrl(config, providerName, opts) | ||
module.authHelper(authUrl) | ||
|
||
if providerName == 'facebook' && !options.display? | ||
options.display = if options.strategy=='redirect' then 'page' else 'popup' | ||
|
||
authUrl = module.authUrl(config, providerName, options) | ||
|
||
if options.strategy == 'redirect' | ||
# Don't do an early return to not break promise chain | ||
window.location.href = authUrl | ||
else | ||
# Classic Popup Strategy | ||
module.authHelper(authUrl, providerName) | ||
|
||
authenticating.promise | ||
|
||
|
@@ -105,7 +157,7 @@ define ['underscore', '../utils/promises', '../utils/version'], (_, promises, ve | |
auth_params = opts || {} | ||
auth_params.app_id = config.appId | ||
# The following is here for backward compatibility. Must be removed at first sight next time | ||
auth_params.callback_url = config.callback_url || config.callbackUrl || module.location.toString() | ||
auth_params.callback_url = opts.redirect_url || config.callback_url || config.callbackUrl || module.location.toString() | ||
auth_params.auth_referer = module.location.toString() | ||
auth_params.version = version | ||
querystring = _.map auth_params,(v,k) -> | ||
|
@@ -121,8 +173,16 @@ define ['underscore', '../utils/promises', '../utils/version'], (_, promises, ve | |
window.__hull_login_status__ = (hash) -> | ||
window.__hull_login_status__ = null | ||
onCompleteAuthentication(hash) | ||
authHelper: (path)-> | ||
w = window.open(path, "_auth", 'location=0,status=0,width=1030,height=600') | ||
authHelper: (path, providerName)-> | ||
|
||
if providerName == 'facebook' | ||
width = 650 | ||
height = 430 | ||
else | ||
width = 1030 | ||
width = 430 | ||
|
||
w = window.open(path, "_auth", "location=0,status=0,width=#{width},height=#{height}") | ||
|
||
# Support for cordova events | ||
if window.device?.cordova | ||
|