Exemple #1
0
        /// <summary>
        /// User login from controller
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="rememberMe"></param>
        /// <param name="database"></param>
        /// <param name="userModel"></param>
        /// <returns></returns>
        public static LoginResult UserLogin(string email, string password, bool rememberMe, HasanEntities database, out UserViewModel userModel)
        {
            userModel = new UserViewModel();

            LoginResult res = new LoginResult();

            try
            {
                User mem = database.User.Where(it => it.EMail == email && !it.Deleted).FirstOrDefault(); // get data for the user
                if (mem == null)
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.MemberNotExist;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.MemberNotExist);
                    return(res);
                }
                if (mem.Password != password) // check user password is valid or not
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.InvalidPassword;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.InvalidPassword);
                    return(res);
                }
                if (!mem.Active) // check user activess
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.MemberIsNotActive;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.MemberIsNotActive);
                    return(res);
                }

                if (DoLogin(email, password, rememberMe, database, out userModel))
                {
                    // var p = Enum.Parse(typeof(FocusConstants.FocusResultCode), FocusConstants.FocusResultCode.Success.ToString());
                    //res.ResponseCode = (FocusConstants)Enum.Parse(typeof(FocusConstants), FocusConstants.FocusResultCode.Success);
                    res.ResponseCode = FocusConstants.FocusResultCode.Success;

                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Success);
                }


                return(res);
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.ErrorException("UserLogin", ex);
                res.ResponseCode    = FocusConstants.FocusResultCode.Exception;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Exception);
                return(res);
            }
        }
        public JsonResult DoLogin(LogInModel model)
        {
            LoginResult   res = new LoginResult();
            UserViewModel userModel;

            if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password))
            {
                res.ResponseCode    = FocusConstants.FocusResultCode.EmailOrPasswordEmpty;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.EmailOrPasswordEmpty);
                return(new JsonResult()
                {
                    Data = res, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            res = UserService.UserLogin(model.Email, model.Password, model.RememberMe, this.database, out userModel);
            //string akey = "";
            //akey = AESCriptography.AesEncryption(userModel.aKey.ToString());
            if (res.ResponseCode == FocusConstants.FocusResultCode.Success)
            {
                res.ResultValue = 1000;
                //  res.ResponseCode = "1000";
                //var identity = new ClaimsIdentity(new[] {
                //new Claim(ClaimTypes.Name, userModel.Name),
                //new Claim(ClaimTypes.Email, userModel.EMail),
                //new Claim(ClaimTypes.GivenName, userModel.Surname),
                //new Claim(ClaimTypes.NameIdentifier, userModel.Id.ToString()),
                //new Claim(ClaimTypes.UserData, akey)
            }
            ;

            //    // Owin login
            //    var ctx = Request.GetOwinContext();
            //    var authManager = ctx.Authentication;
            //    authManager.SignIn(identity);

            //    // Set cookie
            //    CookieManager.SetOwinCookie(model.RememberMe, userModel.gKey.ToString());
            //}

            if (userModel.ChangePasswordAtNextLogon == true)
            {
                res.ResponseCode = FocusConstants.FocusResultCode.ChangePassword;
            }
            return(new JsonResult()
            {
                Data = res, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #3
0
        /// <summary>
        /// Email forgotten password
        /// </summary>
        /// <param name="email"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public static ForgetPasswordResult EmailForgottenPassword(string email, HasanEntities database)
        {
            ForgetPasswordResult res = new ForgetPasswordResult();

            try
            {
                if (string.IsNullOrEmpty(email))
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.EmailAddressIsNull;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.EmailAddressIsNull);
                    return(res);
                }
                User mem = database.User.Where(it => it.EMail == email && !it.Deleted).FirstOrDefault();
                if (mem == null)
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.MemberNotExist;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.MemberNotExist);
                    return(res);
                }
                if (!mem.Active)
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.MemberIsNotActive;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.MemberIsNotActive);
                    return(res);
                }

                if (SendForgatePasswordMail(mem.EMail, mem.Password))
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.Success;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Success);
                }


                return(res);
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.ErrorException("EmailForgottenPassword", ex);
                res.ResponseCode    = FocusConstants.FocusResultCode.Exception;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Exception);
                return(res);
            }
        }
Exemple #4
0
        public static LoginResult UserLoginBygkey(string gkey, bool RememberMe, HasanEntities database, out UserViewModel userModel)
        {
            LoginResult res = new LoginResult();

            userModel = new UserViewModel();
            try
            {
                if (DoLoginBygkey(gkey, database, out userModel))
                {
                    res.ResponseCode    = FocusConstants.FocusResultCode.Success;
                    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Success);
                }
                return(res);
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.ErrorException("UserLoginBygkey", ex);
                res.ResponseCode    = FocusConstants.FocusResultCode.Exception;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Exception);
                return(res);
            }
        }
Exemple #5
0
        /// <summary>
        /// Change Next login password
        /// </summary>
        /// <param name="PIN"></param>
        /// <param name="userId"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public static ProfileResult ChangeNextLoginPassrord(string OldPassword, string NewPassword, string ConfirmPassrord, int userId, HasanEntities database)
        {
            ProfileResult res = new ProfileResult();

            if (string.IsNullOrEmpty(OldPassword))
            {
                res.ResponseCode    = FocusConstants.FocusResultCode.OldPasswordEmpty;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.OldPasswordEmpty);
                return(res);
            }
            if (string.IsNullOrEmpty(NewPassword))
            {
                res.ResponseCode    = FocusConstants.FocusResultCode.NewPasswordEmpty;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.NewPasswordEmpty);
                return(res);
            }
            if (string.IsNullOrEmpty(ConfirmPassrord))
            {
                res.ResponseCode    = FocusConstants.FocusResultCode.ConfirmPasswordEmpty;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.ConfirmPasswordEmpty);
                return(res);
            }
            else if (!IsMatchPassword(OldPassword, userId, database))
            {
                res.ResponseCode    = FocusConstants.FocusResultCode.InvalidOldPassword;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.InvalidOldPassword);
                return(res);
            }
            else if (NewPassword != ConfirmPassrord)
            {
                res.ResponseCode    = FocusConstants.FocusResultCode.NewAndConfirmPasswordMissmatch;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.NewAndConfirmPasswordMissmatch);
                return(res);
            }
            else
            {
                //Regex regex = new Regex(@"" + Core.GlobalProperty.FocusConfUserPasswordFormat);
                //Match match = regex.Match(NewPassword);
                //if (!match.Success)
                //{
                //    res.ResponseCode = FocusConstants.FocusResultCode.InvalidPasswordFormat;
                //    res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.InvalidPasswordFormat);
                //    return res;
                //}
            }
            try
            {
                User entity = database.User.Where(it => it.Id == userId).SingleOrDefault();
                entity.Password = NewPassword;
                entity.ChangePasswordAtNextLogon = false;
                database.SaveChanges();
                res.ResponseCode    = FocusConstants.FocusResultCode.PasswordChangeSuccess;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.PasswordChangeSuccess);
                return(res);
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.ErrorException("ChangePassword", ex);
                res.ResponseCode    = FocusConstants.FocusResultCode.Exception;
                res.ResponseMessage = FocusMessage.GetResourceResultCodeValue(FocusConstants.FocusResultCode.Exception);
                return(res);
            }
        }