Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- formulario.$inject = ['$scope', 'obtenerDatos', '$state', '$timeout'];
- function formulario($scope, obtenerDatos, $state, $timeout) {
- $scope.login = function() {
- var datos, datosRespuesta;
- datos = {
- Usuario: $scope.usuariotxt,
- Password: $scope.passwordtxt
- };
- if (typeof datos.usuario === 'undefined' && typeof datos.Password === 'undefined') {
- $scope.respuesta = "Los campos estan vacios";
- } else {
- $state.go('Loading');
- obtenerDatos.Autenticacion(datos).then(function(response) {
- if (response.data) {
- datosRespuesta = response.data;
- if (datosRespuesta === "Usuario no registrado" ||
- datosRespuesta === "Contraseña incorrecta") {
- $scope.respuesta = datosRespuesta
- $timeout(function() {
- $scope.respuesta = datosRespuesta;
- $state.go('login');
- }, 1000);
- } else {
- obtenerDatos.setDatosUsuarios(datosRespuesta);
- if (datosRespuesta.estudiante) {
- obtenerDatos.insertarDatosEstu(datosRespuesta);
- } else {
- obtenerDatos.insertarDatosDoc(datosRespuesta);
- };
- $state.go('Loading');
- $timeout(function() {
- $state.go(datosRespuesta.estudiante ? 'menuestu' : 'menuprof');
- }, 3000);
- };
- } else {
- console.log(response.status);
- $scope.respuesta = "Error en la solicitud";
- $state.go('login');
- };
- });
- };
- };
- };
- obtenerDatos.$inject = ['$http', '$httpParamSerializer', '$cordovaSQLite'];
- var datosIngreso, datosUsuario;
- function Autenticacion(datos) {
- var url = 'http://190.109.185.138/Apipedro/api/login';
- return $http.post(url, $httpParamSerializer(datos), {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- });
- };
- function getDatos(info) {
- datosIngreso = info;
- };
- function setDatos() {
- return datosIngreso;
- };
- /*Estudiante*/
- function insertarDatosEstu(datosRespuesta) {
- var db, Perfil, Horario, row, crearTablaPerfil, guardarPerfil, crearTablaHorario, guardarHorario, eliminarPerfil, dropPerfil, dropHorario, Usuario, largo, i;
- datosUsuario = datosRespuesta;
- Perfil = datosRespuesta.estudiante;
- Horario = datosRespuesta.materias;
- largo = Horario.length;
- crearTablaPerfil = "CREATE TABLE IF NOT EXISTS Estudiante(Cedula integer primary key, Nombre text, Apellido text, Rol integer, Facultad text, Programa text, Semestre integer)";
- guardarPerfil = "INSERT INTO Estudiante(Cedula, Nombre, Apellido, Rol, Facultad, Programa, Semestre) VALUES(?,?,?,?,?,?,?)";
- crearTablaHorario = "CREATE TABLE IF NOT EXISTS Horario(Codigo text primary key, Grupo integer," +
- "Nombre text, Creditos integer, Dia text, Hora text, Lugar text," +
- "Nota1 float, Nota2 float, Nota3 float)";
- guardarHorario = "INSERT INTO Horario(Codigo, Grupo, Nombre, Creditos, Dia, Hora, Lugar, Nota1, Nota2, Nota3) n
- VALUES(?,?,?,?,?,?,?,?,?,?)";
- dropPerfil = "DROP TABLE Estudiante";
- dropHorario = "DROP TABLE Horario"
- db = $cordovaSQLite.openDB({
- name: "unicesar.db"
- });
- $cordovaSQLite.execute(db, dropPerfil);
- $cordovaSQLite.execute(db, dropHorario);
- $cordovaSQLite.execute(db, crearTablaPerfil);
- $cordovaSQLite.execute(db, crearTablaHorario);
- $cordovaSQLite.execute(db, guardarPerfil, [Perfil.CeduEstu, Perfil.NombEstu, Perfil.ApelEstu, Perfil.RolEstu, Perfil.FacuEstu, Perfil.ProgEstu, Perfil.Semestre]);
- for (i = 0; i < largo; i++) {
- $cordovaSQLite.execute(db, guardarHorario, [Horario[i].CodiAsig, Horario[i].Grupo, Horario[i].NombAsig, Horario[i].Creditos, Horario[i].DiaAsig, Horario[i].HoraAsig, Horario[i].LugarAsig, Horario[i].Nota1, Horario[i].Nota2, Horario[i].Nota3]);
- }
- Usuario = "Estudiante";
- return Usuario;
- };
- /*Docente*/
- function insertarDatosDoc(datosRespuesta) {
- var db, Perfil, Horario, row, crearTablaPerfil_P, guardarPerfil_P, crearTablaHorario_P, guardarHorario_P, crearTablaGrupo,
- insertarGrupos, dropPerfil_P, dropHorario_P, dropGrupos, Usuario, Largo_Horario, Lista, Largo_Grupo, i, k, Cantidad_Estu,
- Nombre_Asig, Asig_Grupo, Asig_Nsp, Grupo, Grupos;
- datosUsuario = datosRespuesta;
- Perfil = datosRespuesta.profesor;
- Horario = datosRespuesta.materias;
- Largo_Horario = Horario.length;
- Grupos = [];
- Grupo = {};
- crearTablaPerfil_P = "CREATE TABLE IF NOT EXISTS Profesor(Cedula integer primary key, Nombre text, Apellido text, Rol integer," +
- " Facultad text, Programa text)";
- guardarPerfil_P = "INSERT INTO Profesor(Cedula, Nombre, Apellido, Rol, Facultad, Programa) VALUES(?,?,?,?,?,?)";
- crearTablaHorario_P = "CREATE TABLE IF NOT EXISTS HorarioP(Codigo text primary key, Grupo integer, Nombre text, Creditos integer," +
- " Dia text, Hora text, Lugar text)";
- guardarHorario_P = "INSERT INTO HorarioP(Codigo, Grupo, Nombre, Creditos, Dia, Hora, Lugar) VALUES(?,?,?,?,?,?,?)";
- crearTablaGrupo = "CREATE TABLE IF NOT EXISTS GruposP(Fila integer primary key, Cedula text, Nombre text," +
- " Apellido text, Nota1 float, Nota2 float, Nota3 float, Habilitacion float, Grupoasig text)";
- insertarGrupos = "INSERT INTO GruposP(Fila, Cedula, Nombre, Apellido, Nota1, Nota2, Nota3, Habilitacion, Grupoasig)" +
- "VALUES(?,?,?,?,?,?,?,?,?)";
- dropPerfil_P = "DROP TABLE Profesor";
- dropHorario_P = "DROP TABLE HorarioP";
- dropGrupos = "DROP TABLE GruposP";
- Cantidad_Estu = 0;
- db = $cordovaSQLite.openDB({
- name: "unicesar.db"
- });
- $cordovaSQLite.execute(db, dropPerfil_P);
- $cordovaSQLite.execute(db, dropHorario_P);
- $cordovaSQLite.execute(db, dropGrupos);
- $cordovaSQLite.execute(db, crearTablaPerfil_P);
- $cordovaSQLite.execute(db, crearTablaHorario_P);
- $cordovaSQLite.execute(db, crearTablaGrupo);
- $cordovaSQLite.execute(db, guardarPerfil_P, [Perfil.CeduProf, Perfil.NombProf, Perfil.ApelProf, Perfil.RolProf, Perfil.FacuProf,
- Perfil.ProgProf
- ]);
- for (i = 0; i < Largo_Horario; i++) {
- $cordovaSQLite.execute(db, guardarHorario_P, [Horario[i].CodiAsig, Horario[i].Grupo, Horario[i].NombAsig,
- Horario[i].Creditos, Horario[i].DiaAsig, Horario[i].HoraAsig, Horario[i].LugarAsig
- ]);
- Lista = Horario[i].Listado
- Largo_Grupo = Lista.length;
- Nombre_Asig = Horario[i].NombAsig;
- Asig_Nsp = Nombre_Asig.replace(/s+/g, '');
- Asig_Grupo = (Asig_Nsp + Horario[i].Grupo);
- Grupo = {
- Nombre: Asig_Nsp + '-' + Horario[i].Grupo,
- Codigo: Asig_Grupo
- };
- Grupos.push(Grupo);
- for (k = 0; k < Largo_Grupo; k++) {
- Cantidad_Estu = Cantidad_Estu + 1;
- $cordovaSQLite.execute(db, insertarGrupos, [Cantidad_Estu, Lista[k].CeduEstu, Lista[k].NombEstu, Lista[k].ApelEstu,
- Lista[k].Nota1, Lista[k].Nota2, Lista[k].Nota3, Lista[k].Habilitacion, Asig_Grupo
- ]);
- }
- }
- localStorage.setItem('GruposProf', JSON.stringify(Grupos));
- Usuario = "Docente";
- return Usuario;
- };
- function getDatosUsuarios() {
- return datosUsuario;
- };
- return {
- Autenticacion: Autenticacion,
- getDatos: getDatos,
- setDatos: setDatos,
- insertarDatosEstu: insertarDatosEstu,
- insertarDatosDoc: insertarDatosDoc,
- getDatosUsuarios: getDatosUsuarios
- };
- };
- angular.module('loadingPage', ['ionic', 'loginApp'])
- .controller('mostrarMensaje', mostrarMensaje)
- .factory('obtenerVista', obtenerVista);
- mostrarMensaje.$inject = ['$scope', 'obtenerVista', '$state', '$timeout', 'obtenerDatos'];
- function mostrarMensaje($scope, obtenerVista, $state, $timeout, obtenerDatos) {
- var vista_Anterior, datosRespuesta;
- vista_Anterior = obtenerVista.nombreVista();
- console.log(vista_Anterior.stateName);
- datosRespuesta = obtenerDatos.getDatosUsuarios();
- $timeout(function() {
- $state.go(datosRespuesta.estudiante ? 'menuestu' : 'menuprof');
- }, 3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement