Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8fb63ec | 2017-08-03 22:46:35 -0700 | [diff] [blame] | 2 | * Copyright 2015 Open Networking Foundation |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 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'; |
| 19 | |
Matteo Scandolo | a3844ec | 2016-06-02 15:45:19 -0700 | [diff] [blame] | 20 | angular.module('mCord') |
| 21 | .directive('cordLogin', function ($log, $location, User) { |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 22 | |
Matteo Scandolo | a3844ec | 2016-06-02 15:45:19 -0700 | [diff] [blame] | 23 | return { |
| 24 | restrict: 'E', |
| 25 | templateUrl: 'app/view/login/login.html', |
| 26 | controllerAs: 'vm', |
| 27 | controller: function(){ |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 28 | |
Matteo Scandolo | a3844ec | 2016-06-02 15:45:19 -0700 | [diff] [blame] | 29 | this.loading = false; |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 30 | |
Matteo Scandolo | a3844ec | 2016-06-02 15:45:19 -0700 | [diff] [blame] | 31 | this.login = () => { |
| 32 | if (this.email && this.password) { |
| 33 | this.loading = true; |
| 34 | User.login(this.email, this.password) |
| 35 | .then(() => { |
| 36 | $location.url('/'); |
| 37 | }) |
| 38 | .catch(() => { |
| 39 | this.error = true; |
| 40 | }) |
| 41 | .finally(() => { |
| 42 | this.loading = false; |
| 43 | }); |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | $log.debug('Cord Login Ctrl has been created.'); |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 48 | } |
Matteo Scandolo | a3844ec | 2016-06-02 15:45:19 -0700 | [diff] [blame] | 49 | } |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 50 | |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 51 | }); |
| 52 | }()); |