Example #1
0
        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);
        }