private void continua_Click(object sender, EventArgs e) { string name = nume.Text; string tel = numar.Text; string nick = nickname.Text; string adr = adresa.Text; string passwrd = pass.Text; string passconf = passconfirmation.Text; if (passwrd == passconf && RegisterController.ValidatePassword(passwrd) == true) { try { RegisterController.Register(name, email, tel, adr, passwrd, nick); Magazin magazin = new Magazin(); magazin.Show(); this.Close(); ConfirmationMail.SendEmail(email, nick); } catch { MessageBox.Show("A aparut o eroare", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Parola este invalida", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IActionResult CheckRegisterConfirmationToken(string token) { //Check if confirmation token exists && that token is not turned in yet ConfirmationMail result = _context.ConfirmationMails.FirstOrDefault(cMail => cMail.ConfirmationToken == token && cMail.AccountStatus == 0); if (result != null) { result.AccountStatus = 1; _context.SaveChanges(); return(new OkObjectResult(true)); } return(new OkObjectResult(false)); }
public IHttpActionResult PostNewUser(UserDTO userRequest) { if (!IsEmailAvailable(userRequest.Email)) { var resp = new HttpResponseMessage(HttpStatusCode.MethodNotAllowed) { Content = new StringContent("Веќе постои корисник со внесената email адреса") }; throw new HttpResponseException(resp); } byte[] salt; rngCsp.GetBytes(salt = new byte[16]); var pdkdf2 = new Rfc2898DeriveBytes(userRequest.Password, salt, 1000); byte[] hash = pdkdf2.GetBytes(20); byte[] hashBytes = new byte[36]; Array.Copy(salt, 0, hashBytes, 0, 16); Array.Copy(hash, 0, hashBytes, 16, 20); byte[] confirmationCode; rngCsp.GetBytes(confirmationCode = new byte[10]); User user = new User { Email = userRequest.Email, Password = Convert.ToBase64String(hashBytes), Salt = Convert.ToBase64String(salt), Role = "unconfirmed", ConfirmationCode = Convert.ToBase64String(confirmationCode), UserDetails = new UserDetails { FirstName = userRequest.FirstName, LastName = userRequest.LastName } }; db.Users.Add(user); db.SaveChanges(); ConfirmationMail.SendConfirmationEmail(user, Request); return(Ok("Account successfully created")); }
public IActionResult Post([FromBody] UserAddress u) {//Create if (u != null && u.User != null) { string confirmationTokenGuid = Guid.NewGuid().ToString(); var emailAlreadyExists = _context.Users.Any(user => user.Email.ToLower() == u.User.Email.ToLower()); if (!emailAlreadyExists) { bool emailHasBeenSend = this.SendEmail(u.User, confirmationTokenGuid); if (emailHasBeenSend) { ConfirmationMail confirmationMail = new ConfirmationMail(); confirmationMail.User = u.User; confirmationMail.AccountStatus = 0;// eerst 0, als hij in de mail link klikt dan 1 confirmationMail.ConfirmationToken = confirmationTokenGuid; u.User.ConfirmationMail = confirmationMail; var hash = (new SHA1Managed()).ComputeHash(Encoding.UTF8.GetBytes(u.User.Password)); var sendHashedPassword = string.Join("", hash.Select(b => b.ToString("x2")).ToArray()); u.User.Password = sendHashedPassword; u.Current = 1; _context.UserAddresses.Add(u); _context.SaveChanges(); return(new OkObjectResult(new { emailSend = true, isError = false, response = "Wij hebben een validatie mail gestuurd naar: " + u.User.Email + ". Klik op de link in deze mail om uw account aan te maken" })); } return(new OkObjectResult(new { emailSend = false, isError = true, response = "De email kon niet verzonden worden, de email bestaat niet" })); } //User already exists return(new ConflictObjectResult(new { emailSend = false, isError = true, response = "Email bestaat al" })); } //Information was incorrect return(new ConflictObjectResult(new { emailSend = false, isError = true, response = "De gegeven informatie is niet correct" })); }
public IActionResult BlockUser(int userId) { ConfirmationMail confirmationMail = this._context.ConfirmationMails.FirstOrDefault(c => c.UserId == userId); if (confirmationMail != null) { bool isUserBlocked = false; if (confirmationMail.AccountStatus == -1) { confirmationMail.AccountStatus = 1; } else { confirmationMail.AccountStatus = -1; isUserBlocked = true; } _context.SaveChanges(); return(new ObjectResult(new { error = false, isBlocked = isUserBlocked })); } return(new ObjectResult(new { error = true, isBlocked = false })); }