Ejemplo n.º 1
0
        public dynamic Login(Usuario user)
        {
            user.senha = HashAuth.GenerateHash(user.senha, user.email);
            var searchUser = con.usuarios.FirstOrDefault(e => e.email == user.email && e.senha == user.senha);

            if (searchUser == null)
            {
                return(false);
            }

            if (searchUser.isAluno)
            {
                var userSearch = con.alunos.FirstOrDefault(e => e.Nickname == searchUser.Nickname);
                rank.RankAt(userSearch.id);
                return(GenerateJSONWebToken(userSearch.id, searchUser.id, "Aluno", userSearch.Nickname));
            }
            if (searchUser.isProfessor)
            {
                var userSearch = con.professores.FirstOrDefault(e => e.Nickname == searchUser.Nickname);
                return(GenerateJSONWebToken(userSearch.id, searchUser.id, "Professor", userSearch.Nickname));
            }
            if (searchUser.isInstituicao)
            {
                var userSearch = con.instituicaos.FirstOrDefault(e => e.Nickname == searchUser.Nickname);
                return(GenerateJSONWebToken(userSearch.id, searchUser.id, "Instituicao", userSearch.Nickname));
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool Cadastro(Usuario user)
        {
            var userSearch = con.usuarios.FirstOrDefault(e => e.Nickname == user.Nickname || e.email == user.email);

            if (userSearch != null)
            {
                return(false);
            }

            var newUser = new Usuario();

            newUser.email    = user.email;
            newUser.senha    = HashAuth.GenerateHash(user.senha, user.email);
            newUser.Nickname = user.Nickname;
            if (user.isAluno)
            {
                newUser.isAluno = true;
                var newAluno = new Aluno();
                newAluno.Nickname = user.Nickname;
                con.alunos.Add(newAluno);
                con.SaveChanges();
            }
            if (user.isProfessor)
            {
                newUser.isProfessor = true;
                var newP = new Professor();
                newP.Nickname = user.Nickname;
                con.professores.Add(newP);
                con.SaveChanges();
            }
            if (user.isInstituicao)
            {
                newUser.isInstituicao = true;
                var newI = new Instituicao();
                newI.Nickname = user.Nickname;
                con.instituicaos.Add(newI);
                con.SaveChanges();
            }
            con.usuarios.Add(newUser);
            con.SaveChanges();
            return(true);
        }