Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('LoginApp', ["firebase", "ngRoute"])
- app.config(function ($routeProvider) {
- $routeProvider
- .when('/', {
- templateUrl: 'registration.html',
- controller: 'AuthCtrl'
- })
- .when('/logIn', {
- templateUrl: 'login.html',
- controller: 'AuthCtrl'
- })
- .when('/User', {
- templateUrl: "User.html",
- controller: 'AuthCtrl'
- })
- .otherwise({
- redirectTo: '/'
- });
- });
- app.factory("Auth", ["$firebaseAuth",
- function($firebaseAuth) {
- var ref = new Firebase("https://uniquecoders.firebaseio.com/");
- return $firebaseAuth(ref);
- }
- ]);
- app.controller("AuthCtrl", ["$scope", "Auth",
- function($scope, Auth) {
- $scope.createUser = function() {
- $scope.message = null;
- $scope.error = null;
- var ref2 = new Firebase("https://uniquecoders.firebaseio.com/");
- ref2.createUser({
- email: $scope.email,
- password: $scope.password
- }, function(error, userData) {
- if (error) {
- switch (error.code) {
- case "EMAIL_TAKEN":
- alert("The new user account cannot be created because the email is already in use. Try to login");
- break;
- case "INVALID_EMAIL":
- alert("The specified email is not a valid email.");
- break;
- case "INVALID_PASSWORD":
- alert("The Specified Passowrd Is not valid.")
- break;
- default:
- alert("Error creating user:", error);
- }
- } else {
- alert("Successfully created user account with uid:", userData.uid);
- alert($scope.UserName)
- window.location.hash = "/User"
- $scope.usernames = "HEY"
- }
- });
- };
- $scope.logIn = function(){
- $scope.message = null;
- $scope.error = null;
- ref2.authWithPassword({
- "email" : $scope.logInemail,
- "password" : $scope.logInemailpassword
- }, function(error, userData){
- if(error){
- alert("Login Failed.")
- console.log(error)
- }
- else{
- alert("Logged In!")
- }
- })
- }
- /* $scope.removeUser = function() {
- $scope.message = null;
- $scope.error = null;
- Auth.$removeUser({
- email: $scope.email,
- password: $scope.password
- }).then(function() {
- $scope.message = "User removed";
- }).catch(function(error) {
- $scope.error = error;
- });
- };*/
- }
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement