luisruiz

Untitled

Nov 25th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. 'use strict';
  2.  
  3. angular.module('myApp.registro', ['ngRoute'])
  4.  
  5. .config(['$routeProvider', function($routeProvider) {
  6. $routeProvider.when('/registro', {
  7. templateUrl: 'registro/registro.html',
  8. controller: 'RegistroCtrl'
  9. });
  10. }])
  11.  
  12. .controller('RegistroCtrl', ['$location','$scope', '$firebase','$cookies', 'auth','moment','$firebaseAuth', function($location,$scope, $firebase, $cookies, auth,moment,$firebaseAuth) {
  13.  
  14. var ref = new Firebase("https://dentalapp.firebaseio.com/users");
  15. var sync = $firebase(ref);
  16.  
  17. var firebaseObj = new Firebase("https://dentalapp.firebaseio.com");
  18. var loginObj = $firebaseAuth(firebaseObj);
  19. var now = moment().format();
  20.  
  21.  
  22. $scope.agregar = function(userNew){
  23. loginObj.$createUser({
  24. email: userNew.email,
  25. password: userNew.password
  26. }).then(function(userData) {
  27. console.log("usuario " + userData.uid + " creado con exito!");
  28.  
  29. return loginObj.$authWithPassword({
  30. email: userNew.email,
  31. password: userNew.password
  32. });
  33. }).then(function(authData) {
  34. console.log("datos correctos de usuario:", authData.uid);
  35.  
  36. sync.$push({
  37. uid: authData.uid,
  38. email: authData.password.email,
  39. nombre:userNew.nombre,
  40. rut:userNew.rut,
  41. FechaIngreso: now,
  42. TipoUser:'user'
  43. }).then(function(ref) {
  44. ref.key(); // key for the new ly created record
  45.  
  46. $scope.user.nombre= '';
  47. $scope.user.email='';
  48. $scope.user.rut='';
  49. $scope.user.password='';
  50. $scope.user.obs='';
  51. $scope.mensaje='Usuario ingresado con exito';
  52. }, function(error) {
  53. console.log("Error:", error);
  54. });
  55.  
  56.  
  57.  
  58. }).catch(function(error) {
  59. console.error("Error: ", error);
  60. });
  61. }
  62.  
  63.  
  64. }]);
Advertisement
Add Comment
Please, Sign In to add comment