Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('fairMuseApp')
- .controller('LoginCtrl', function(authenticationService, $location, $scope) {
- var self = this;
- var user, email, password, authenticationService, response, wrongCredentials, location;
- location = $location
- self.email = "";
- self.password = "";
- self.wrongCredentials = false;
- self.sendForm = function(email, password) {
- self.user = {email: self.email,
- password: self.password}
- var promise = authenticationService.login(self.user);
- promise.then(success, error);
- };
- var success = function(response){
- localStorage.setItem('auth_token', response.data.auth_token);
- console.log(localStorage)
- location.path('/songs')
- };
- var error = function(hi) {
- self.wrongCredentials = true;
- };
- });
- <div ng-include="'views/navbar.html'"></div>
- <div ng-controller='LoginCtrl as login' class='alert alert-danger' ng-show="login.wrongCredentials">
- Wrong Credentials
- </div>
- <form name="login_form" ng-submit="login.sendForm(email, password)">
- <label for="email">Email</label>
- <input type="email" name="email" ng-model="login.email">
- <label for="password">Password</label>
- <input type="password" name="password" ng-model="login.password">
- <button type="submit">Log in</button>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement