private LoginModel AuthenticateLogin(LoginModel model) { try { model.ResponseCode = 99; Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AuthenticateUser(model.UserName); if (employeeMaster != null) { string passowrd = employeeMaster.Password; string userId = employeeMaster.UserId.ToString(); if (passowrd.Equals(model.Password.Trim().EncodePasswordToBase64())) { model.Name = employeeMaster.EmployeeName + " (" + employeeMaster.EmployeeCode + ")"; model.UserId = Convert.ToInt32(userId); model.ResponseCode = 200; model.Message = "Success"; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); } else { model.Message = "Invalid username/password."; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.WrongPassword; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Invalid username/password."; auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } catch (Exception ex) { new Logger().LogException(ex, "AuthenticateLogin"); model.Message = ex.Message; } return(model); }
private LoginModel UserAutoLogin(LoginModel model) { try { model.ResponseCode = 99; Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AutoAuthenticateUserByDevice(model.DeviceId); if (employeeMaster != null) { string userId = employeeMaster.UserId.ToString(); if (employeeMaster.IsPasswordChangeRequired) { model.ResponseCode = 99; model.Message = "Reset password needed. Please visit aegiscrm.in to reset password."; } else if (!employeeMaster.IsLoginActive) { model.ResponseCode = 99; model.Message = "Login blocked by admin."; } else { model.Name = employeeMaster.EmployeeName + " (" + employeeMaster.EmployeeCode + ")"; model.UserId = Convert.ToInt32(userId); model.ResponseCode = 200; model.Message = "Success"; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Device not registered. Please login with username and password."; auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = model.DeviceId; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } catch (Exception ex) { new Logger().LogException(ex, "UserAutoLogin"); model.Message = ex.Message; } return(model); }
private void UserLogin() { try { Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AuthenticateUser(txtUserName.Text); if (employeeMaster != null) { string passowrd = employeeMaster.Password; string userId = employeeMaster.UserId.ToString(); if (employeeMaster.IsActive && passowrd.Equals(txtPassword.Text.Trim().EncodePasswordToBase64())) { if (employeeMaster.IsLoginActive) { string roles = employeeMaster.Roles; string userSettings = new Business.Settings.UserSettings().GetByUserId(Convert.ToInt32(userId)).Tables[0].Rows[0]["UserSettings"].ToString(); roles = string.Concat(roles, userSettings); Business.Common.Context.Username = employeeMaster.EmployeeName; Business.Common.Context.Image = employeeMaster.Image; Business.Common.Context.UserGender = employeeMaster.GenderId; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, userId, DateTime.Now, DateTime.Now.AddHours(2), false, roles, //define roles here "/"); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); Response.Cookies.Add(cookie); auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); if (employeeMaster.IsPasswordChangeRequired) { Response.Redirect(@"ResetPassword.aspx"); } else { Response.Redirect(@"Dashboard.aspx"); } } else { lblUserMessage.InnerHtml = "Login blocked by admin."; lblUserMessage.Visible = true; } } else { auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.WrongPassword; auth.Client = GetClient(); auth.FailedUserName = txtUserName.Text; auth.FailedPassword = txtPassword.Text; objEmployeeMaster.Login_Save(auth); lblUserMessage.InnerHtml = "Invalid Username/Password"; lblUserMessage.Visible = true; } } else { auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = txtUserName.Text; auth.FailedPassword = txtPassword.Text; objEmployeeMaster.Login_Save(auth); lblUserMessage.InnerHtml = "Invalid Username/Password"; lblUserMessage.Visible = true; } } catch (Exception ex) { ex.WriteException(); lblUserMessage.InnerHtml = "Invalid Username/Password"; lblUserMessage.Visible = true; } }
private LoginModel UserLogin(LoginModel model) { try { model.ResponseCode = 99; Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AuthenticateUser(model.UserName); if (employeeMaster != null) { string passowrd = employeeMaster.Password; string userId = employeeMaster.UserId.ToString(); if (passowrd.Equals(model.Password.Trim().EncodePasswordToBase64())) { DataTable dtDevices = objEmployeeMaster.LinkedDevices_GetByUserId(employeeMaster.UserId); if (dtDevices != null && dtDevices.Rows.Count > 0) { model.ResponseCode = 99; model.Message = "A device is already linked with you. Please contact admin to change device."; } else if (employeeMaster.IsPasswordChangeRequired) { model.ResponseCode = 99; model.Message = "Reset password needed. Please visit aegiscrm.in to reset password."; } else if (!employeeMaster.IsLoginActive) { model.ResponseCode = 99; model.Message = "Login blocked by admin."; } else { model.Name = employeeMaster.EmployeeName + " (" + employeeMaster.EmployeeCode + ")"; model.UserId = Convert.ToInt32(userId); model.ResponseCode = 200; model.Message = "Success"; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Invalid username/password."; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.WrongPassword; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Invalid username/password."; auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } catch (Exception ex) { new Logger().LogException(ex, "UserLogin"); model.Message = ex.Message; } return(model); }