protected override void OnPreRender(EventArgs e) { string resetIdentifyer = Request.QueryString["resetId"]; if (resetIdentifyer != null && resetIdentifyer.Length == 64) { using (var db = CLinq.DataContext.Create()) { var passwordReset = db.PasswordResets.Where(pr => pr.ResetIdentyfier == resetIdentifyer).Take(1).SingleOrDefault(); if (passwordReset == null) { NotAuthenticatedPanel.Visible = true; Label errorMessage = new Label(); errorMessage.Text = "Angivet id är felaktigt!"; NotAuthenticatedPanel.Controls.Add(errorMessage); } else { CuplexLib.User user = CuplexLib.User.GetOne(passwordReset.UserRef); AccessControl.CreateUserSession(user.UserName); db.PasswordResets.DeleteBatch(pr => pr.UserRef == user.UserRef); AuthenticatedPanel.Visible = true; } } } }
protected void CreateUserButton_Clicked(object sender, EventArgs e) { string userName = UserNameTextBox.Text; string password = PasswordTextBox.Text; string emailAddress = EmailAddressTextBox.Text; if (userName == "" || password == "" || emailAddress == "") { return; } //Check if user exists if (CuplexLib.User.UserNameExists(userName)) { ShowModalMessage(Utils.GetResourceText("RegisterUserUsernameTaken")); return; } else if (!Utils.ValidateEmail(emailAddress)) { ShowModalMessage(Utils.GetResourceText("RegisterUserIncorrectEmailAddress")); return; } else if (password != PasswordConfirmTextBox.Text) { ShowModalMessage(Utils.GetResourceText("RegisterUserPasswordMissmatch")); return; } //Verify password strength PasswordVerifier passwordVerifier = new PasswordVerifier(); PasswordVerifier.PasswordVerifierResult passwordVerificationResult = passwordVerifier.VerifyPassword(password); if (passwordVerificationResult != PasswordVerifier.PasswordVerifierResult.PasswordIsOk) { string errorMessage = "<b>" + Utils.GetResourceText(Enum.GetName(typeof(PasswordVerifier.PasswordVerifierResult), passwordVerificationResult)) + "</b>"; errorMessage += "<BR/>" + string.Format(Utils.GetResourceText("PasswordRules"), passwordVerifier.MinimumPasswordLength, passwordVerifier.MinimumPasswordCapitalLetters, passwordVerifier.MinimumPasswordDigits); ShowModalMessage(errorMessage); return; } //Verify UserName if (!UserNameVerifier.VerifyUserName(userName)) { ShowModalMessage(Utils.GetResourceText("IncorrectUserName")); return; } CuplexLib.User createdUser = CuplexLib.User.CreateUser(userName, password, emailAddress); if (createdUser != null) { AccessControl.CreateUserSession(createdUser.UserName); Response.Redirect(cms.Current.GetRootPath); } }
protected void LoginButton_Clicked(object sender, EventArgs e) { User.UserAuthenticateResponce authenticationResponce = User.AuthenticateUser(UserNameTextBox.Text, PasswordTextBox.Text); if (authenticationResponce == User.UserAuthenticateResponce.UnknownUser) { Session["LastError"] = "Användaren hittades inte."; Response.Redirect(cms.Current.GetRootPath + "user/createuser"); } else if (authenticationResponce == User.UserAuthenticateResponce.PasswordIncorrect) { Session["LastError"] = "Felaktigt lösenord."; Response.Redirect(cms.Current.GetRootPath + "user/login"); } else { AccessControl.CreateUserSession(UserNameTextBox.Text); Response.Redirect(cms.Current.GetRootPath); } }
protected void UserPanelLoginButton_Clicked(object sender, EventArgs e) { string userName = UserName2TextBox.Text; string password = Password2TextBox.Text; User.UserAuthenticateResponce authenticationResponce = CuplexLib.User.AuthenticateUser(userName, password); if (authenticationResponce == CuplexLib.User.UserAuthenticateResponce.UnknownUser) { Session["LastError"] = "Användaren hittades inte."; //Response.Redirect(cms.Current.GetRootPath + "user/createuser"); } else if (authenticationResponce == CuplexLib.User.UserAuthenticateResponce.PasswordIncorrect) { Session["LastError"] = "Felaktigt lösenord."; //Response.Redirect(cms.Current.GetRootPath + "user/login"); } else { AccessControl.CreateUserSession(userName); Response.Redirect(cms.Current.GetRootPath); } }