public async Task <IActionResult> Register([Bind("UserID,Email,Name,Password,ConfirmedEmail,Street,PostalCode,City,Phone,DateOfBirth,RoleID")] Users users) { if (ModelState.IsValid == true) { if (!_context.Users.Any(x => x.Email == users.Email)) { /** Password encrypting ***/ /*var data = Encoding.ASCII.GetBytes(users.Password); * var sha256 = new SHA256CryptoServiceProvider(); * var sha256data = sha256.ComputeHash(data); * users.Password = sha256data;*/ /** End of Password encrypting **/ users.RoleID = 2; _context.Add(users); await _context.SaveChangesAsync(); /** Send Confirmation Email **/ int user_id = (from user in _context.Users select user.UserID).Max(); var result = new MailSenderController(_configuration).PostMessage(users.Email, users.Name, users.UserID); /** End of Confirmation Email **/ // Register User as a Customer on Stripe StripeLib stripeLib = new StripeLib(); users.CustomerId = await stripeLib.CreateCustomer(users); await _context.SaveChangesAsync(); insertToRegisterTable(); TempData["Message"] = "A sua conta foi criada com sucesso!Por favor verifique o seu email e clique no email para concluir o registo da sua conta e prosseguir para o login!"; return(RedirectToAction("Index", "Home", null)); } ModelState.AddModelError("Email", "Email já existe!"); return(View(users)); } return(View(users)); }
public async Task <IActionResult> Create([Bind("UserID,Email,Name,Password,ConfirmedEmail,Street,PostalCode,City,Phone,DateOfBirth,RoleID")] Users users) { if (!GetAuthorization(1, 'c')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (!checkValues(users)) { ViewBag.RoleTypes = _context.Roles.AsParallel(); return(View(users)); } if (ModelState.IsValid) { _context.Add(users); await _context.SaveChangesAsync(); /** Send Confirmation Email **/ int user_id = (from user in _context.Users select user.UserID).Max(); var result = new MailSenderController(_configuration).PostMessage(users.Email, users.Name, users.UserID); /** End of Confirmation Email **/ // Register User as a Customer on Stripe StripeLib stripeLib = new StripeLib(); users.CustomerId = await stripeLib.CreateCustomer(users); await _context.SaveChangesAsync(); insertToRegisterTable(); TempData["Message"] = "Utilizador criado com sucesso!Por favor, o utilizador que verifique o seu email e clique no link para concluir o registo da sua conta e para prosseguir para o login!"; return(RedirectToAction(nameof(Index))); } TempData["Message"] = "Por favor, siga os exemplos para continuar!"; ViewBag.RoleTypes = _context.Roles.AsParallel(); return(View()); }