Exemple #1
0
        public String cadastro(User user)
        {
            var collection = database.GetCollection <User>("user");

            if (user.Cpf == null || user.Cpf.Equals(""))
            {
                return("invalid_cpf");
            }
            if (user.Password == null || user.Password.Equals(""))
            {
                return("invalid_password");
            }
//            var result = validatePasswordStrenght(user.Password);
            if (user.Rg == null || user.Rg.Equals(""))
            {
                return("invalid_rg");
            }
            if (user.Name == null || user.Name.Equals(""))
            {
                return("invalid_name");
            }
            var filter  = new BsonDocument("Cpf", user.Cpf);
            var results = collection.Find(filter).ToList();

            if (results.Count > 0)
            {
                return("user_existent");
            }

            Cript cript = new Cript();


            user.Password   = cript.ComputeSha256Hash(user.Password);
            user.StartDate  = DateTime.Now.Date;
            user.UserStatus = UserStatus.NORMAL;
            user.Profile    = 2;

            collection.InsertOne(user);


            return("success");
        }
Exemple #2
0
        public User Login(string cpf, string senha)
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");

            var filter  = new BsonDocument("Cpf", cpf);
            var results = collection.Find(filter).ToList();

            if (results.Count == 0)
            {
                throw new Exception("Usuario inexistente ");
            }

            User user = results.First();

            Cript cript = new Cript();

            if (user.UserStatus == UserStatus.DELETED)
            {
                throw new Exception("Usuario inexistente ");
            }

            if (user.UserStatus == UserStatus.BLOQUED)
            {
                throw new Exception("Usuario Bloqueado");
            }

            if (!user.Password.Equals(cript.ComputeSha256Hash(senha)))
            {
                throw new WrongcredentialsException("Senha Invalida");
            }


            return(user);
        }