750340d184b4faedb0b87a8e176837aa7238889a
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / dlux / dlux-web / src / common / login / login.controller.js
1 /*
2  * Copyright (c) 2014 Inocybe Technologies, and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 define(['common/login/login.module', 'common/authentification/auth.services'], function(login) {
10
11   login.controller('LoginCtrl', function ($scope, $http, $window, Auth, $location) {
12         // default values
13         $scope.login = {};
14         $scope.login.username = "";
15         $scope.login.password = "";
16         $scope.login.remember = false;
17         $scope.rememberme = true;
18
19         $scope.sendLogin = function () {
20             Auth.login($scope.login.username, $scope.login.password, $scope.success, $scope.errorDisplay);
21         };
22
23         $scope.success = function(response) {
24             $window.location.href = 'index.html';
25         };
26         $scope.errorDisplay = function (error) {
27            $scope.error = "Unable to login";
28
29         };
30     });
31
32     login.controller('forgotPasswordCtrl', function ($scope, $http) {
33         $scope.recover = {};
34         $scope.recover.email = "";
35         $scope.sendForgotPassword = function () {
36             $http.post('/recover', $scope.recover).success(function (data) {
37                 if (data.recover) {
38                     console.log("email sent");
39                 }
40                 else {
41                     console.log("email not sent");
42                 }
43             });
44
45         };
46     });
47
48    login.controller('registerCtrl', function ($scope, $http) {
49         $scope.register = {};
50         $scope.register.email = "";
51         $scope.register.username = "";
52         $scope.register.password = "";
53         $scope.register.repeatPassword = "";
54         $scope.register.userAgreement = false;
55
56         $scope.sendRegister = function () {
57             $http.post('/register', $scope.register).success(function (data) {
58                 if (data.register) {
59                     console.log("registration is successful");
60                 }
61                 else {
62                     console.log("registration failed");
63                 }
64             });
65         };
66     });
67 });