Exemplo n.º 1
0
        public LoginUserResponse Login(LoginUserRequest request)
        {
            var response = new LoginUserResponse();

            try
            {
                //var user = DataContext.Users.Where(x => x.Username == request.Username).Include(x => x.Role).First();
                var user = DataContext.Users.Where(x => x.Email == request.Email).Include(x => x.Role).Include(y => y.RolePrivileges).First();
                if (user != null && user.Password == crypto.Compute(request.Password, user.PasswordSalt))
                {
                    //Add For Update Password
                    int HashIteration = int.Parse(user.PasswordSalt.Substring(0, user.PasswordSalt.IndexOf('.')),System.Globalization.NumberStyles.Number);
                    if (HashIteration > 10)
                    {
                        ChangePassword(new ChangePasswordRequest
                        {
                            Id = user.Id,
                            Old_Password = request.Password,
                            New_Password = request.Password
                        });
                    }
                    //Include(x => x.Role).
                    response = user.MapTo<LoginUserResponse>();
                    response.IsSuccess = true;
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message = string.Format("Failed login using email <{0}> and password <{1}>", request.Email, request.Password);
                }
            }
            catch (System.InvalidOperationException x)
            {

                response.IsSuccess = false;
                response.Message = string.Format("Failed login using email <{0}> and password <{1}> {2}", request.Email, request.Password, x.Message);
            }

            return response;
        }
Exemplo n.º 2
0
        public LoginUserResponse Login(LoginUserRequest request)
        {
            var response = new LoginUserResponse();

            try
            {
                //var user = DataContext.Users.Where(x => x.Username == request.Username).Include(x => x.Role).First();
                var user = DataContext.Users.Where(x => x.Email == request.Email).Include(x => x.Role).First();
                if (user != null && user.Password == crypto.Compute(request.Password, user.PasswordSalt))
                {
                    //Include(x => x.Role).
                    response = user.MapTo<LoginUserResponse>();
                    response.IsSuccess = true;
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message = string.Format("Failed login using email <{0}> and password <{1}>", request.Email, request.Password);
                }
            }
            catch (System.InvalidOperationException x)
            {

                response.IsSuccess = false;
                response.Message = string.Format("Failed login using email <{0}> and password <{1}> {2}", request.Email, request.Password, x.Message);
            }

            return response;
        }