Blame view
scripts/LoginController.js
2.1 KB
4da3dd303
|
1 |
angular.module('flashy.LoginController', ['ui.router']). |
ce4a4542e
|
2 |
|
80d1e57aa
|
3 |
controller('LoginController', ['$scope', '$state', '$http', 'UserService', |
6fd36f978
|
4 |
function($scope, $state, $http, UserService) { |
80d1e57aa
|
5 6 7 8 |
'use strict'; $scope.uniqueError = false; $scope.loginError = false; |
6fd36f978
|
9 |
$scope.login = function(email, password) { |
80d1e57aa
|
10 11 12 13 |
$http.post('/api/login', JSON.stringify({ 'email': email, 'password': password })). |
6fd36f978
|
14 |
success(function(data) { |
80d1e57aa
|
15 16 17 18 |
UserService.getUserData(); $state.go('feed'); console.log(data); }). |
6fd36f978
|
19 |
error(function(data, status, header, config) { |
80d1e57aa
|
20 21 22 23 24 25 |
if (data.detail) { // assume 'invalid email or pass' $scope.loginError = true; } console.log(data); }); }; |
6fd36f978
|
26 |
$scope.signUp = function(email, password) { |
80d1e57aa
|
27 28 29 30 |
$http.post('/api/register', JSON.stringify({ 'email': email, 'password': password })). |
6fd36f978
|
31 |
success(function(data) { |
80d1e57aa
|
32 33 34 |
$state.go('feed'); console.log(data); }). |
6fd36f978
|
35 |
error(function(data, status, headers, config) { |
80d1e57aa
|
36 37 38 39 40 41 42 43 44 45 46 47 48 |
console.log(data.email); if (data.email == 'This field is required.') { $scope.invalid = true; $scope.uniqueError = false; } else if (data.email) { // assume 'email not unique' error $scope.uniqueError = true; $scope.invalid = false; } console.log(data); }); }; |
6fd36f978
|
49 |
$scope.triggerPasswordReset = function() { |
80d1e57aa
|
50 51 52 53 |
$state.go('requestpasswordreset'); }; } ]); |