From 1232eb1c070a6446f54c13caea03663b5f7a0c8a Mon Sep 17 00:00:00 2001 From: Hovhannes Kuloghlyan Date: Tue, 26 May 2015 22:58:44 +0400 Subject: [PATCH] [FEATURE] Login: Remember me and redirect after login --- src/js/tabs/login.controller.js | 38 ++++++++++++++++++--------------- src/templates/tabs/login.jade | 16 +++++++++----- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/js/tabs/login.controller.js b/src/js/tabs/login.controller.js index 2b51f1e10..50342d2dd 100644 --- a/src/js/tabs/login.controller.js +++ b/src/js/tabs/login.controller.js @@ -19,8 +19,18 @@ LoginTab.prototype.extraRoutes = [ ]; LoginTab.prototype.angular = function(module) { - module.controller('LoginCtrl', ['$scope', '$location', 'rpTracker', 'rpId', - function($scope, $location, rpTracker, id) { + module.controller('LoginCtrl', ['$scope', '$location', '$sce', 'rpTracker', 'rpId', + function($scope, $location, $sce, rpTracker, id) { + + $scope.error = ''; + $scope.redirectTo = $location.path(); + $scope.backendMessages = []; + $scope.authAction = $sce.trustAsResourceUrl(Options.backend_url + '/auth/login'); + + if (id.loginStatus) { + $location.path('/balance'); + return; + } function loginCallback(err) { if (err) { @@ -36,13 +46,11 @@ LoginTab.prototype.angular = function(module) { return; } - $location.path('/balance').search(''); - - /* - if ($.isEmptyObject($routeParams)) { - $location.path('/balance'); - } - */ + if ($location.search().redirect_to) { + $location.path($location.search().redirect_to).search(''); + } else { + $location.path('/balance').search(''); + } rpTracker.track('Login', { 'Status': 'success' @@ -51,14 +59,10 @@ LoginTab.prototype.angular = function(module) { $scope.status = ''; } - $scope.error = ''; - $scope.rememberMe = true; - $scope.backendMessages = []; - - if (id.loginStatus) { - $location.path('/balance'); - return; - } + $scope.submitForm = function(authAction) { + $scope.redirectTo = $location.path(); + $scope.authAction = $sce.trustAsResourceUrl(Options.backend_url + '/auth/' + authAction); + }; // if ($routeParams.callback === 'callback' && $routeParams.token ) { if ($location.path() === '/login/callback' && $location.search().token) { diff --git a/src/templates/tabs/login.jade b/src/templates/tabs/login.jade index d4ed57c41..12387540c 100644 --- a/src/templates/tabs/login.jade +++ b/src/templates/tabs/login.jade @@ -10,11 +10,17 @@ section.col-xs-12.content(ng-controller="LoginCtrl") br .backend.error(ng-repeat="message in backendMessages") span.error(ng-bind="message") - .submit-btn-container - a.btn.btn-submit.btn-block.btn-success#registerBtn(href="{{globalOptions.backend_url}}/auth/register") - span(l10n) Sign up - a.btn.btn-submit.btn-block.btn-success#loginBtn(href="{{globalOptions.backend_url}}/auth/login") - span(l10n) Sign in + form(name='loginForm' action='{{authAction}}') + .submit-btn-container + button.btn.btn-submit.btn-block.btn-success#registerBtn(type="submit" ng-click="submitForm('register')") + span(l10n) Sign Up + button.btn.btn-submit.btn-block.btn-success#loginBtn(type="submit" ng-click="submitForm('login')") + span(l10n) Sign In + .input-group.col-xs-12 + input(name='redirect_to', type='hidden', value='{{redirectTo}}') + label + input.rememberMe(name='remember_me', type='checkbox') + span(for='remember_me', l10n) Remember me on this device for 30 days .row.switch-mode-wrapper .switch-mode-link-container.bottomText(l10n) | Ripple Trade uses