Advertisement
Guest User

Untitled

a guest
Jan 9th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. var app = angular.module('LoginApp', ["firebase", "ngRoute"])
  2.  
  3. app.config(function ($routeProvider) {
  4. $routeProvider
  5. .when('/', {
  6. templateUrl: 'registration.html',
  7. controller: 'AuthCtrl'
  8. })
  9. .when('/logIn', {
  10. templateUrl: 'login.html',
  11. controller: 'AuthCtrl'
  12. })
  13.  
  14. .when('/User', {
  15. templateUrl: "User.html",
  16. controller: 'AuthCtrl'
  17. })
  18. .otherwise({
  19. redirectTo: '/'
  20. });
  21.  
  22.  
  23. });
  24.  
  25.  
  26. app.factory("Auth", ["$firebaseAuth",
  27. function($firebaseAuth) {
  28. var ref = new Firebase("https://uniquecoders.firebaseio.com/");
  29. return $firebaseAuth(ref);
  30. }
  31. ]);
  32.  
  33.  
  34. app.controller("AuthCtrl", ["$scope", "Auth",
  35. function($scope, Auth) {
  36.  
  37.  
  38. $scope.createUser = function() {
  39.  
  40. $scope.message = null;
  41. $scope.error = null;
  42. var ref2 = new Firebase("https://uniquecoders.firebaseio.com/");
  43. ref2.createUser({
  44. email: $scope.email,
  45. password: $scope.password
  46. }, function(error, userData) {
  47. if (error) {
  48. switch (error.code) {
  49. case "EMAIL_TAKEN":
  50. alert("The new user account cannot be created because the email is already in use. Try to login");
  51. break;
  52. case "INVALID_EMAIL":
  53. alert("The specified email is not a valid email.");
  54. break;
  55. case "INVALID_PASSWORD":
  56. alert("The Specified Passowrd Is not valid.")
  57. break;
  58. default:
  59. alert("Error creating user:", error);
  60. }
  61. } else {
  62. alert("Successfully created user account with uid:", userData.uid);
  63. alert($scope.UserName)
  64.  
  65. window.location.hash = "/User"
  66. $scope.usernames = "HEY"
  67. }
  68. });
  69.  
  70.  
  71. };
  72.  
  73. $scope.logIn = function(){
  74. $scope.message = null;
  75. $scope.error = null;
  76.  
  77. ref2.authWithPassword({
  78. "email" : $scope.logInemail,
  79. "password" : $scope.logInemailpassword
  80.  
  81. }, function(error, userData){
  82.  
  83. if(error){
  84. alert("Login Failed.")
  85. console.log(error)
  86. }
  87. else{
  88. alert("Logged In!")
  89. }
  90.  
  91. })
  92.  
  93. }
  94.  
  95. /* $scope.removeUser = function() {
  96. $scope.message = null;
  97. $scope.error = null;
  98.  
  99. Auth.$removeUser({
  100. email: $scope.email,
  101. password: $scope.password
  102. }).then(function() {
  103. $scope.message = "User removed";
  104. }).catch(function(error) {
  105. $scope.error = error;
  106. });
  107. };*/
  108. }
  109. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement