コード例 #1
0
        public static void StoreUser(User user)
        {
            ctx = new CheqStoreContext();

            user.Password = CredentialsRepository.EncryptingPassword(user.Password);
            ctx.Users.Add(user);
            ctx.SaveChanges();
        }
コード例 #2
0
        /// <summary>
        /// Procesa el Login para poder comparar las credenciales y dar o no acceso cargandolo en la sesion.
        /// Here below process the login to comparing the credentials and give or not access in the current session
        /// </summary>
        /// <param name="loginClass"></param>
        /// <returns> string</returns>
        public static ResponseEntity ProccessingLogin(LoginClass loginClass, string rol = "Cliente")
        {
            if (loginClass == null)
            {
                return responseEntity = new ResponseEntity()
                {
                           status = false, message = "El login no puede ser nulo"
                }
            }
            ;

            //Here I compare the credentials with encrypting password
            string EncryptingPassword = CredentialsRepository.EncryptingPassword(loginClass.Password);

            User credentials;

            if (rol == "Cliente")
            {
                credentials = ctx.Users.FirstOrDefault(x => x.Username == loginClass.Username && x.Password == EncryptingPassword && x.Rol.ToString() == rol);
            }
            else
            {
                credentials = ctx.Users.FirstOrDefault(x => x.Username == loginClass.Username && x.Password == EncryptingPassword && x.Rol.ToString() != "Cliente");
            }

            if (credentials == null)
            {
                return responseEntity = new ResponseEntity()
                {
                           status = false, message = "Los datos no coinciden, por favor revisar"
                }
            }
            ;

            CredentialsRepository.CreateSession(credentials.Username);

            return(responseEntity = new ResponseEntity()
            {
                status = true, message = ""
            });
        }
    }
}
コード例 #3
0
        public static ResponseEntity StoreRegister(RegisterRequest registerRequest)
        {
            if (CredentialsRepository.busyUsername(registerRequest.Username))
            {
                return responseEntity = new ResponseEntity()
                {
                           status = false, message = "El usuario ya está ocupado, pruebe con otro por favor"
                }
            }
            ;

            try
            {
                User userEntity = new User()
                {
                    Name     = registerRequest.Name,
                    Username = registerRequest.Username,
                    Password = CredentialsRepository.EncryptingPassword(registerRequest.Password),
                };

                ctx.Users.Add(userEntity);
                ctx.SaveChanges();

                return(responseEntity = new ResponseEntity()
                {
                    status = true, message = ""
                });
            }
            catch (Exception e)
            {
                return(responseEntity = new ResponseEntity()
                {
                    status = false, message = "Error al grabar el usuario desde register, -> " + e.Message
                });
            }
        }
    }
コード例 #4
0
        public static void UpdateUser(User user)
        {
            User   originalUser = GetByID(user.UserID);
            string Password     = originalUser.Password;

            using (ctx = new CheqStoreContext())
            {
                user.Password = (string.IsNullOrWhiteSpace(user.Password)) ? Password: CredentialsRepository.EncryptingPassword(user.Password);

                ctx.Entry(user).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }
        }