LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Sign Up

Email:
Username:
Password:

Welcome {{currentUser.get('username')}}

You have been successfully logged in

JS
//Parse connection to the app
Parse.initialize("1mRpcxlCSH1AcLlpC8dLUIBQLScKmNxOcYmRsa0Z", "QQ8cXlyYJmFwUSh4Q2J9fhelbEdlI8eepZcqlAvH")

angular.module('AuthApp', [])

.run(['$rootScope', function($scope) {
  $scope.currentUser = Parse.User.current(); //set currentUser to Parse current user if available.

  /* what happens when login is clicked. 
    myname and mypass are passed into the parse login function and checked against the database
  */
  $scope.login = function(form) {
    var myname = form.username;
    var mypass = form.password;

    Parse.User.logIn(myname, mypass, {
      success: function(user) {
        $scope.currentUser = user;
        $scope.$apply() // notify angular to synch current user eg refresh
      },
      error: function(user, error) {
        alert("unable to login: " + error.code + " " + error.message);
      }
    });
  }

  /*
    signup function 
    form inputs are set into the variable user and then the parse signup function is called.
  */
  $scope.signUp = function(form) {
    var user = new Parse.User();
    user.set('email', form.email);
    user.set('username', form.username);
    user.set('password', form.password);

    user.signUp(null, {
      success: function(user) {
        $scope.currentUser = user;
        $scope.$apply() //notify angular to synch current user eg refresh 
      },
      error: function(user, error) {
        alert("unable to sign up: " + error.code + " " + error.message);
      }
    })
  }

  /*
    on logOut function.
    parse logout
    current user = null
  */
  $scope.logOut = function(form) {
    Parse.User.logOut();
    $scope.currentUser = null;
  }
}])
Host Instantly Drag and Drop Website Builder

 

Description

Angular login, singup app connecting with parse.
Term
Wed, 11/29/2017 - 11:25

Related Codes

Pen ID
Pen ID
Pen ID