Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form role="form" ng-submit="controller.register()">
- <div ng-show="controller.user.username.length > 20">Username must be 20 characters or less.</div>
- <br>
- <div ng-show="controller.user.username = null">Username is blank.</div>
- <br>
- <input type="text" name="username" ng-model="controller.user.username" placeholder="Choose a username."/>
- <br/>
- <div ng-show="controller.user.password = null">Password is blank.</div>
- <br>
- <input type="password" name="password" ng-model="controller.user.password" placeholder="Choose a password."/>
- <input class="button" type="submit" value="Submit">
- <div>{{controller.msg}}</div>
- </form>
- wishingWell.controller('register', function($http, $location, $rootScope) {
- var noerrors = false;
- var self = this;
- self.user = {};
- self.msg = undefined;
- if (self.user.username != null && self.user.username.length <= 20 && self.user.password != null) {
- noerrors = true;
- }
- self.register = function() {
- if (noerrors) {
- $http.post('register', user).success(function (response) {
- if (response.data.code == "200") {
- $rootScope.authenticated = true;
- $location.path("/user-home");
- } else {
- msg = response.data.msg;
- $location.path("/sign-up");
- }
- });
- } else {
- $location.path("/sign-up");
- }
- };
- });
- wishingWell.controller('navigation',
- function($rootScope, $http, $location) {
- var self = this;
- var authenticate = function(credentials, callback) {
- var headers = credentials ? {authorization : "Basic "
- + btoa(credentials.username + ":" + credentials.password)
- } : {};
- $http.get('user', {headers : headers}).then(function(response) {
- if (response.data.name) {
- $rootScope.authenticated = true;
- } else {
- $rootScope.authenticated = false;
- }
- callback && callback();
- }, function() {
- $rootScope.authenticated = false;
- callback && callback();
- });
- }
- authenticate();
- self.credentials = {};
- self.login = function() {
- authenticate(self.credentials, function() {
- if ($rootScope.authenticated) {
- $location.path("/");
- self.error = false;
- } else {
- $location.path("/login");
- self.error = true;
- }
- });
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement