Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | (function () { |
| 18 | 'use strict'; |
Bri Prebilic Cole | 0e371dc | 2015-06-05 16:47:21 -0700 | [diff] [blame] | 19 | var urlSuffix = '/rs/login'; |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 20 | |
| 21 | angular.module('cordLogin', []) |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 22 | .controller('CordLoginCtrl', |
| 23 | ['$log', '$scope', '$resource', '$location', '$window', |
| 24 | function ($log, $scope, $resource, $location, $window) { |
Bri Prebilic Cole | 0e371dc | 2015-06-05 16:47:21 -0700 | [diff] [blame] | 25 | var LoginData, resource; |
| 26 | $scope.page.curr = 'login'; |
| 27 | |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 28 | function getResource(email) { |
Bri Prebilic Cole | 0e371dc | 2015-06-05 16:47:21 -0700 | [diff] [blame] | 29 | LoginData = $resource($scope.shared.url + urlSuffix + '/' + email); |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 30 | resource = LoginData.get({}, |
| 31 | function () { |
| 32 | $location.url('/home'); |
| 33 | $window.location.href = $location.absUrl(); |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | $scope.login = function () { |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 38 | if ($scope.email && $scope.password) { |
| 39 | getResource($scope.email); |
Bri Prebilic Cole | 105d8d7 | 2015-06-09 11:47:13 -0700 | [diff] [blame] | 40 | $scope.shared.login = $scope.email; |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 41 | } |
Bri Prebilic Cole | 0e371dc | 2015-06-05 16:47:21 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | $log.debug('Cord Login Ctrl has been created.'); |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 45 | }]); |
| 46 | }()); |