blob: df4c4a84a4e10dc111c970d339cd2a82a24b7848 [file] [log] [blame]
Matteo Scandolobf14f882016-06-02 10:01:34 -07001/*
Brian O'Connor8fb63ec2017-08-03 22:46:35 -07002 * Copyright 2015 Open Networking Foundation
Matteo Scandolobf14f882016-06-02 10:01:34 -07003 *
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 Scandoloa3844ec2016-06-02 15:45:19 -070020 angular.module('mCord')
21 .directive('cordLogin', function ($log, $location, User) {
Matteo Scandolobf14f882016-06-02 10:01:34 -070022
Matteo Scandoloa3844ec2016-06-02 15:45:19 -070023 return {
24 restrict: 'E',
25 templateUrl: 'app/view/login/login.html',
26 controllerAs: 'vm',
27 controller: function(){
Matteo Scandolobf14f882016-06-02 10:01:34 -070028
Matteo Scandoloa3844ec2016-06-02 15:45:19 -070029 this.loading = false;
Matteo Scandolobf14f882016-06-02 10:01:34 -070030
Matteo Scandoloa3844ec2016-06-02 15:45:19 -070031 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 Scandolobf14f882016-06-02 10:01:34 -070048 }
Matteo Scandoloa3844ec2016-06-02 15:45:19 -070049 }
Matteo Scandolobf14f882016-06-02 10:01:34 -070050
Matteo Scandolobf14f882016-06-02 10:01:34 -070051 });
52}());