コード例 #1
0
        public ActionResult Login(string username, string password)
        {
            try
            {
                var userInfo = _userInformationService.GetUserDetails(null, username);
                if (userInfo == null)
                {
                    return(Json(new { result = "Username or password is incorrect. Please enter your valid credentials.", url = Url.Action("Index", "Home") }));
                }

                if (Authenticator.ValidatePassword(password.Trim(), userInfo.Password))
                {
                    if (!userInfo.IsActive || userInfo.IsLocked)
                    {
                        return(Json(new { val = 1, result = "User is not active now. Please contact with your system administrator.", url = Url.Action("Index", "Home") }));
                    }

                    SetLoginInformation(userInfo);
                    if (userInfo.IsPasswordChanged)
                    {
                        return(Json(new
                        {
                            val = 2,
                            result = "Welcome " + userInfo.EmployeeName,
                            url = Url.Action("Index", "Home")
                        }));
                    }
                    return(Json(new { val = 3, result = "Change your password", url = @Url.Action("PasswordChange", "UserInformation", new { area = "SecurityAdministration" }) }));
                }
                return(Json(new { result = "Username or password is incorrect. Please enter your valid credentials.", url = Url.Action("Index", "Home") }));
            }
            catch (Exception exception)
            {
                if (exception.Message.Contains("The underlying provider failed on Open"))
                {
                    return(Json(new { result = "Failed to connect database server. Please contact with your system administrator.", url = Url.Action("Index", "Home") }));
                }
            }
            return(Json(new { result = "Application service is not available now. Please try again later." }));
        }
コード例 #2
0
ファイル: LoginForm.cs プロジェクト: EnggJibon/HR-Management
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                var userInformation = _userInformationService.GetUserDetails(null, txtUsername.Text.Trim());
                if (userInformation == null)
                {
                    MessageBox.Show(@"Username or password is incorrect. Please enter your valid credentials.");
                    return;
                }

                if (Authenticator.ValidatePassword(txtPassword.Text.Trim(), userInformation.Password))
                {
                    if (!userInformation.IsActive || userInformation.IsLocked)
                    {
                        MessageBox.Show(@"User is not active now. Please contact with your system administrator.");
                    }

                    if (userInformation.IsPasswordChanged)
                    {
                        LoginInformation.UserInformation = userInformation;

                        Hide();
                        var dashboard = new Dashboard();
                        dashboard.Closed += (o, args) => Close();
                        dashboard.Show();

                        MessageBox.Show(@"Login Successful.");
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception.Message.Contains("The underlying provider failed on Open"))
                {
                    MessageBox.Show(@"Failed to connect database server. Please contact with your system administrator.");
                }
            }
        }
コード例 #3
0
 public JsonResult Get(long id)
 {
     return(new JsonResult {
         Data = _userInformationService.GetUserDetails(id, "")
     });
 }