public async Task <UserAccountInformation> EditAccount(Guid id) { var user = await _userManager.FindByIdAsync(id.ToString()); if (user == null) { return(null); } var userRoles = await _userManager.GetRolesAsync(user); var userClaims = await _userManager.GetClaimsAsync(user); var model = new UserAccountInformation() { FirstName = user.FirstName, LastName = user.LastName, UserName = user.UserName, Email = user.Email, PhoneNumber = user.PhoneNumber, Gender = user.Gender, Birthday = user.Birthday, Claims = userClaims.Select(c => c.Value).ToList(), Roles = userRoles }; return(model); }
public async Task <IActionResult> Delete(Guid id, UserAccountInformation collection) { try { await _unitOfWork.UserAccount.RemoveAccount(id); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <UserAccountInformation> GetAccount(Guid id) { var user = await _userManager.FindByIdAsync(id.ToString()); if (user == null) { return(null); } var userRoles = await _userManager.GetRolesAsync(user); var userClaims = await _userManager.GetClaimsAsync(user); var model = new UserAccountInformation() { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, UserName = user.UserName, Email = user.Email, PhoneNumber = user.PhoneNumber, Gender = user.Gender, Birthday = user.Birthday, Claims = userClaims.Select(c => c.Value).ToList(), Roles = userRoles.ToList() }; //var user = await _userManager.FindByIdAsync(id.ToString()); //if (user == null) //{ // return null; //} //var userRoles = await _userManager.GetRolesAsync(user); //var model = new UserAccountInformation() //{ // FirstName = user.FirstName, // LastName = user.LastName, // UserName = user.UserName, // Email = user.Email, // PhoneNumber = user.PhoneNumber, // Gender = user.Gender, // Birthday = user.Birthday, // Roles = userRoles //}; return(model); }
private bool fcnLogin(LoginModel model, ref User user, ref UserAccountInformation userAccountInfo, int LoginOrReset) { ValidateUserLogin objValidateUserLogin = null; // main class LoginUserMiscInfo objLoginUserMiscInfo = null; // Login validate information UserModel ObjUser = null; UserAccountModel ObjUserAccount = null; string strUsername = model.UserName; string strPassword = model.ResetPassword = model.Password; bool blnLogin = false; //added BY Rakesh Kumar on 13 June 2013 LoginUserData try { objValidateUserLogin = new ValidateUserLogin(); // main class objLoginUserMiscInfo = new LoginUserMiscInfo(); // Login validate information ObjUser = new UserModel(); ObjUserAccount = new UserAccountModel(); // UserAccount information objValidateUserLogin = _loginService.ValidateUserLogin(model.UserName.Trim(), model.Password.Trim(), LoginOrReset, "http://www.newspaperarchive.com", Session.SessionID);////third parameter 0 is for Reset login . //if (objValidateUserLogin != null) if (objValidateUserLogin.User != null && objValidateUserLogin.FBUser != null && objValidateUserLogin.UserAccount != null && objValidateUserLogin.LoginUserMiscInfo != null) { objLoginUserMiscInfo = objValidateUserLogin.LoginUserMiscInfo; ObjUser = objValidateUserLogin.User; ObjUserAccount = objValidateUserLogin.UserAccount; if (ObjUser != null && objLoginUserMiscInfo != null && ObjUserAccount != null) blnLogin = true; } if (blnLogin) { int? LoggedInStatus = objLoginUserMiscInfo.UserIsLive; //var CheckEncryptedLoginCookie = GetCookieValue(".ASPXAUTH"); //Added By Rakesh //if (LoggedInStatus > 0 && string.IsNullOrEmpty(CheckEncryptedLoginCookie)) if (LoggedInStatus > 0) { model.loginMessage = "<div class=\"alert-panel\"><div class=\"alert alert-error\"><button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>" + "<b>User already logged in at: " + String.Format("{0:MMM d yyyy}", objLoginUserMiscInfo.LoginTime) + ". Your account is showing you are logged in. More than one person can not be logged in under " + "the same username. Please click on the \"Yes. Log me in and end the other session.\" button.</b></div></div>"; //////////"the same username. Please re-enter your user name and password then click on the reset button.</b></div></div>"; model.isConcurrent = true; blnLogin = false; return blnLogin; } HttpCookie cookies = new HttpCookie(_config.GetStringValueFromConfig("cookiePrefix", "NewspaperARCHIVE.com") + ".shoppingCart"); cookies = Request.Cookies[_config.GetStringValueFromConfig("cookiePrefix", "NewspaperARCHIVE.com") + ".shoppingCart"]; if (cookies != null) { cookies.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cookies); } //userAccountInfo = _userAccountService.GetActiveAccountByUserId(user.UserId); Na.Core.Cookies.clsCookies clsCookie = new Na.Core.Cookies.clsCookies(); if (objLoginUserMiscInfo == null) { blnLogin = false; } else { // var RoleId = 0; if (objLoginUserMiscInfo.WebsiteID == 1 && objLoginUserMiscInfo.ActiveAccount == 1) { //roleId = Convert.ToInt32(objLoginInformatin.RoleId); //var websiteRole = _webRoles.GetWebsiteRoleById(roleId); String WebsiteRoleName = objLoginUserMiscInfo.WebsiteRoleName; // if Role Name exists then Proceed ahead else escape this conditions if (!string.IsNullOrEmpty(WebsiteRoleName)) { if (ObjUserAccount.EndDate < DateTime.Now) { Response.Cookies.Add(clsCookie.fcnCreateValidationCookie(Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserId.ToString()), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.Password), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserName), objLoginUserMiscInfo.EmailAddress, ObjUser.FirstName, ObjUser.LastName, "7", "Expired", _common.GetStringValue(ObjUserAccount.PlanId, string.Empty), "", ConfigurationManager.AppSettings["cookieTimeout"].ToString(), ConfigurationManager.AppSettings["cookiePrefix"].ToString())); } else { Response.Cookies.Add(clsCookie.fcnCreateValidationCookie(Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserId.ToString()), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.Password), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserName), objLoginUserMiscInfo.EmailAddress, ObjUser.FirstName, ObjUser.LastName, ObjUserAccount.RoleId.ToString(), objLoginUserMiscInfo.WebsiteRoleName, _common.GetStringValue(ObjUserAccount.PlanId, string.Empty), "", ConfigurationManager.AppSettings["cookieTimeout"].ToString(), ConfigurationManager.AppSettings["cookiePrefix"].ToString())); } // int? webSiteIdForURL = objLoginUserMiscInfo.WebSiteIdForReport; //// below functionality is handled by Sproc--by Rakesh Kumar on Dated 13 june 2013 // _userService.ReportUserLogin(objLoginInformatin.UserID, "http://www.newspaperarchive.com", Session.SessionID); } } else { //if (objLoginUserMiscInfo.ActiveAccount >= 0) //{ // Response.Cookies.Add(clsCookie.fcnCreateValidationCookie(Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserId.ToString()), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.Password), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserName), objLoginUserMiscInfo.EmailAddress, ObjUser.FirstName, ObjUser.LastName, "7", "Expired", _common.GetStringValue(ObjUserAccount.PlanId, string.Empty), "", ConfigurationManager.AppSettings["cookieTimeout"].ToString(), ConfigurationManager.AppSettings["cookiePrefix"].ToString())); // blnLogin = true; //} //else //{ Response.Cookies.Add(clsCookie.fcnCreateValidationCookie(Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserId.ToString()), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.Password), Na.Core.Helpers.SecureNPASecurity.Encryption.EncryptText(ObjUser.UserName), objLoginUserMiscInfo.EmailAddress, ObjUser.FirstName, ObjUser.LastName, "7", "Expired", _common.GetStringValue(ObjUserAccount.PlanId, string.Empty), "", ConfigurationManager.AppSettings["cookieTimeout"].ToString(), ConfigurationManager.AppSettings["cookiePrefix"].ToString())); blnLogin = true; //} } } } else { blnLogin = false; Redirect(Na.Core.Configuration.NaConfig.Url.DomainUrl + "/login?value=invalid"); } if (blnLogin) { Session["testUSer"] = model.UserName; UpdateSharedLoggedInUserInfo(objValidateUserLogin); } } //catch (Exception) { } finally { objLoginUserMiscInfo = null; ObjUser = null; ObjUserAccount = null; objValidateUserLogin = null; } return blnLogin; }
public ActionResult Reset(LoginModel model, string ReturnUrl) { if (ValidateResetLogOn(model)) { // if (!String.IsNullOrWhiteSpace(ReturnUrl) && !ReturnUrl.ToLower().Contains("http://" + Request.Url.Host.ToLower())) { ReturnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + "/" + ReturnUrl.Replace("//", "/"); } //Done by Rachna/S on 27 jan 14 w.r.t to #348 if (!String.IsNullOrWhiteSpace(ReturnUrl) && !ReturnUrl.ToLower().Contains("http://" + Request.Url.Host.ToLower())) { if (ReturnUrl.StartsWith("/")) { ReturnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + ReturnUrl; } else { ReturnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + "/" + ReturnUrl; } } string returnUrl = (ReturnUrl != null) ? ReturnUrl : model.ReturnUrl; var user = new User(); var userAccount = new UserAccountInformation(); // bool lblogin = fcnLoginReset(model, ref user, ref userAccount); int status = (int)LoginOrReset.Reset; bool lblogin = fcnLogin(model, ref user, ref userAccount, status);// using same function for Login & Reset, last parameter distinguish it. if (lblogin) { //sign in new user _authenticationService.SignIn(user, model.RememberMe); if (!String.IsNullOrEmpty(returnUrl) && !returnUrl.ToLower().Contains("login")) return Redirect(returnUrl); else return Redirect(Na.Core.Configuration.NaConfig.Url.DomainUrl + "/myaccount"); } else { if (!model.isConcurrent) { model.loginMessage = string.Empty; model.loginMessage = "<div class=\"alert-panel\"><div class=\"alert alert-success\"><button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>" + "The username and/or password you have provided cannot be found in our records.</div></div>"; } //*************** Start .. this block is add by Rakesh to implement remember Me 19 July 2013 ****************** // Check if cookie exists & authenticatin is failed then clear the cookie as passsword may be changed. var CheckASPXAUTHCookie = GetCookieValue(FormsAuthentication.FormsCookieName); if (CheckASPXAUTHCookie != "") { _authenticationService.SignOut(); // newly aded By Rakesh on 19 July 2013 lbloginIfValidateFromCookie = false; // In case of false return redirect to Login again(i.e authenticatin from cokiee is not successful ) BY Rakesh 19 July 2013 //return Redirect(Na.Core.Configuration.NaConfig.Url.DomainUrl + "/login"); } //************************************************ End ****************** } } return View(model); }
public ActionResult Login(LoginModel model, string ReturnUrl) { Na.Core.SharedInfo _sharedInfo = new Na.Core.SharedInfo(); ModelState.Remove("EmailAddess");// Added By Rakesh: purpose: on login button click validatin for forgot password email also arises : done on 02 August 2013. if (ValidateLogOn(model)) { // if (!String.IsNullOrWhiteSpace(ReturnUrl) && !ReturnUrl.ToLower().Contains("http://" + Request.Url.Host.ToLower())) { ReturnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + "/" + ReturnUrl.Replace("//", "/"); } // Done by Rachna/S on 27 jan 14 w.r.t to #348 if (!String.IsNullOrWhiteSpace(ReturnUrl) && !ReturnUrl.ToLower().Contains("http://" + Request.Url.Host.ToLower())) { if (ReturnUrl.StartsWith("/")) { ReturnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + ReturnUrl; } else { ReturnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + "/" + ReturnUrl; } } string returnUrl = (ReturnUrl != null) ? ReturnUrl : model.ReturnUrl; var user = new User(); var userAccount = new UserAccountInformation(); int status = (int)LoginOrReset.Login;// Added By Rakesh kumar get the value from Enum bool lblogin = fcnLogin(model, ref user, ref userAccount, status); if (lblogin) { //sign in new user user = _sharedInfo.ConvertUserModelToUser(_sharedInfo.LoggedInUserInfo.User); _authenticationService.SignIn(user, model.RememberMe); #region Redirect After Login by Chandi@20130124 string PageLists = _common.GetStringValue(_config.GetStringValueFromConfig("RedirectControllAfterLogin", string.Empty), string.Empty); if (isRedirectControllPageAfterLogin(PageLists, returnUrl.Replace(Na.Core.Configuration.NaConfig.Url.DomainUrl + "/", ""))) { var _url = fcnRedirectedPage(); if (!String.IsNullOrWhiteSpace(_url)) { returnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + "/" + _url; } else { returnUrl = Na.Core.Configuration.NaConfig.Url.DomainUrl + "/browse"; } } #endregion if (!String.IsNullOrEmpty(returnUrl) && !returnUrl.ToLower().Contains("login")) return Redirect(returnUrl); else return Redirect(Na.Core.Configuration.NaConfig.Url.DomainUrl + "/myaccount"); } else { if (!model.isConcurrent) { model.loginMessage = string.Empty; model.loginMessage = "<div class=\"alert-panel\"><div class=\"alert alert-success\"><button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>" + "The username and/or password you have provided cannot be found in our records.</div></div>"; } } } return View(model); }