Commit 58f9d45f277a79b69cb4c9c76b257c724712b126
1 parent
1236efbf
Exists in
master
and in
6 other branches
Improve oauth login/signup
Showing
2 changed files
with
20 additions
and
4 deletions
Show diff stats
index.html
| @@ -397,8 +397,12 @@ | @@ -397,8 +397,12 @@ | ||
| 397 | <label for="user_password_confirmation" class="label">Confirme a senha:</label> | 397 | <label for="user_password_confirmation" class="label">Confirme a senha:</label> |
| 398 | <input id="user_password_confirmation" name="password_confirmation" type="password" placeholder="Confirme a senha"> | 398 | <input id="user_password_confirmation" name="password_confirmation" type="password" placeholder="Confirme a senha"> |
| 399 | </div> | 399 | </div> |
| 400 | + <div class="oauth-providers"> | ||
| 401 | + <input id="user_oauth_providers" name="oauth_providers" type="hidden"> | ||
| 402 | + </div> | ||
| 400 | <div class="captcha col-sm-12"> | 403 | <div class="captcha col-sm-12"> |
| 401 | <div id="g-recaptcha"></div> | 404 | <div id="g-recaptcha"></div> |
| 405 | + </div> | ||
| 402 | </div> | 406 | </div> |
| 403 | <div class="actions col-sm-12"> | 407 | <div class="actions col-sm-12"> |
| 404 | <div class="row"> | 408 | <div class="row"> |
js/main.js
| @@ -188,7 +188,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -188,7 +188,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 188 | $('.talk-proposal-container').hide(); | 188 | $('.talk-proposal-container').hide(); |
| 189 | }, | 189 | }, |
| 190 | 190 | ||
| 191 | - loginCallback: function(loggedIn, token) { | 191 | + loginCallback: function(loggedIn, token, user) { |
| 192 | logged_in = loggedIn; | 192 | logged_in = loggedIn; |
| 193 | $('.login .message').text(''); | 193 | $('.login .message').text(''); |
| 194 | 194 | ||
| @@ -200,6 +200,16 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -200,6 +200,16 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 200 | loginButton.siblings('.require-login .message').show(); | 200 | loginButton.siblings('.require-login .message').show(); |
| 201 | loginButton.siblings('.login-container').hide(); | 201 | loginButton.siblings('.login-container').hide(); |
| 202 | $.cookie('_dialoga_session', Main.private_token); | 202 | $.cookie('_dialoga_session', Main.private_token); |
| 203 | + } else if (user) { | ||
| 204 | + var loginContainer = loginButton.siblings('.login-container'); | ||
| 205 | + loginContainer.show(); | ||
| 206 | + loginContainer.find('.new-user').click(); | ||
| 207 | + var signupForm = loginContainer.find('#signup-form'); | ||
| 208 | + signupForm.find("#user_email").val(user.email); | ||
| 209 | + signupForm.find("#user_name").val(user.login); | ||
| 210 | + signupForm.find("#user_oauth_providers").val(user.oauth_providers); | ||
| 211 | + signupForm.find(".password").hide(); | ||
| 212 | + signupForm.find(".password-confirmation").hide(); | ||
| 203 | } else { | 213 | } else { |
| 204 | loginButton.siblings('.require-login').hide(); | 214 | loginButton.siblings('.require-login').hide(); |
| 205 | loginButton.siblings('.login-container').show(); | 215 | loginButton.siblings('.login-container').show(); |
| @@ -714,11 +724,13 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -714,11 +724,13 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 714 | $(document).on('click', '.new-user', function(e) { | 724 | $(document).on('click', '.new-user', function(e) { |
| 715 | var loginForm = $(this).parents('#login-form'); | 725 | var loginForm = $(this).parents('#login-form'); |
| 716 | var signupForm = loginForm.siblings('#signup-form'); | 726 | var signupForm = loginForm.siblings('#signup-form'); |
| 717 | - | 727 | + |
| 718 | loginForm.hide(); | 728 | loginForm.hide(); |
| 719 | signupForm.show(); | 729 | signupForm.show(); |
| 730 | + signupForm.find(".password").show(); | ||
| 731 | + signupForm.find(".password-confirmation").show(); | ||
| 720 | loginForm.find('.message').hide(); | 732 | loginForm.find('.message').hide(); |
| 721 | - console.log(signupForm.find('#g-recaptcha')[0]); | 733 | + signupForm.find('#g-recaptcha').empty(); |
| 722 | grecaptcha.render(signupForm.find('#g-recaptcha')[0], {'sitekey' : window.recaptchaSiteKey }); | 734 | grecaptcha.render(signupForm.find('#g-recaptcha')[0], {'sitekey' : window.recaptchaSiteKey }); |
| 723 | e.preventDefault(); | 735 | e.preventDefault(); |
| 724 | }) | 736 | }) |
| @@ -785,7 +797,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -785,7 +797,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 785 | 797 | ||
| 786 | window.addEventListener("message", function(ev) { | 798 | window.addEventListener("message", function(ev) { |
| 787 | if (ev.data.message === "oauthClientPluginResult") { | 799 | if (ev.data.message === "oauthClientPluginResult") { |
| 788 | - Main.loginCallback(ev.data.logged_in, ev.data.private_token); | 800 | + Main.loginCallback(ev.data.logged_in, ev.data.private_token, ev.data.user); |
| 789 | ev.source.close(); | 801 | ev.source.close(); |
| 790 | } | 802 | } |
| 791 | }); | 803 | }); |