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 }; }
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; } }
/// <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; } }