Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('myApp.registro', ['ngRoute'])
- .config(['$routeProvider', function($routeProvider) {
- $routeProvider.when('/registro', {
- templateUrl: 'registro/registro.html',
- controller: 'RegistroCtrl'
- });
- }])
- .controller('RegistroCtrl', ['$location','$scope', '$firebase','$cookies', 'auth','moment','$firebaseAuth', function($location,$scope, $firebase, $cookies, auth,moment,$firebaseAuth) {
- var ref = new Firebase("https://dentalapp.firebaseio.com/users");
- var sync = $firebase(ref);
- var firebaseObj = new Firebase("https://dentalapp.firebaseio.com");
- var loginObj = $firebaseAuth(firebaseObj);
- var now = moment().format();
- $scope.agregar = function(userNew){
- loginObj.$createUser({
- email: userNew.email,
- password: userNew.password
- }).then(function(userData) {
- console.log("usuario " + userData.uid + " creado con exito!");
- return loginObj.$authWithPassword({
- email: userNew.email,
- password: userNew.password
- });
- }).then(function(authData) {
- console.log("datos correctos de usuario:", authData.uid);
- sync.$push({
- uid: authData.uid,
- email: authData.password.email,
- nombre:userNew.nombre,
- rut:userNew.rut,
- FechaIngreso: now,
- TipoUser:'user'
- }).then(function(ref) {
- ref.key(); // key for the new ly created record
- $scope.user.nombre= '';
- $scope.user.email='';
- $scope.user.rut='';
- $scope.user.password='';
- $scope.user.obs='';
- $scope.mensaje='Usuario ingresado con exito';
- }, function(error) {
- console.log("Error:", error);
- });
- }).catch(function(error) {
- console.error("Error: ", error);
- });
- }
- }]);
Advertisement
Add Comment
Please, Sign In to add comment