public async Task<ActionResult> Register(RegisterViewModel model) { Random rand = new Random(); if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, NumberOfCameras = 0, CompanyId = model.CompanyId, Approved = false }; const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?#%&½"; var password = "******"; for (int i = 0; i < 10; i++) { password = password + chars[rand.Next(0, chars.Length)]; } var result = await UserManager.CreateAsync(user, password); if (result.Succeeded) { var welcome = $"<h2>Hello and welcome to the Svalbard Challenge - The opportunity of a lifetime! </h2> <br/> <br/> Use you e-mail, <b> {model.Email} </b>, and your password <b> {password} </b> to log in. By logging on to the website the first time you are automatically agreeing to the following terms and conditions for the competition: <br/> <br/>- Only sales made by competitors individually will be approved, no cartels are allowed <br/>- Only sales in a store or from telephone will be approved, no online sales.<br/>- Only products delivered from FUJIFILM Nordic will be approved<br/>- In case of any irregularities the competitor must be able to prove sales by enclosing receipts or corresponding proof.<br/><br/>FUJIFILM Nordic reserves the right to:<br/><br/>Make changes in the scoring system at any time during the competition<br/>Exclude any or all competitors if any form of cheating is detected, such as registering not sold products or registering sold products on another competitor etc.<br/><br/>Any taxes will be paid by the winner(s)of the competition.<br/><br/><br/>Your registration will now be processed and you will be approved, within 24 hours.<br/><br/><br/><br/><br/><br/>Kind regards,<br/><br/><br/>FUJIFILM Nordic<br/><br/><br/><br/>ffnr - [email protected]"; var mailer = new Mailer(); mailer.Mail(model.Email, "Welcome to the Fujifilm Svalbard Challenge!", welcome); return RedirectToAction("Index", "Home"); } AddErrors(result); } model.GetCompanies = new GetCompaniesViewModel { Companies = new List<Company>() }; var context = HttpContext.GetOwinContext().Get<ApplicationDbContext>(); var companies = context.Companies; foreach (var company in companies) { model.GetCompanies.Companies.Add(company); } // If we got this far, something failed, redisplay form return View(model); }
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist or is not confirmed return View("ForgotPasswordConfirmation"); } try { string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); var mailer = new Mailer(); mailer.Mail(model.Email, "Glömt lösenord till Fuji", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); } catch (Exception) { return View(model); } return RedirectToAction("ForgotPasswordConfirmation", "Account"); } // If we got this far, something failed, redisplay form; return View(model); }
public async Task<string> ApproveUser(string input) { var userId = input; FujiRepository.ApproveUser(userId); var message = "Dear competitor,<br/><br/>Your registration has now been approved.<br/>Use you e-mail, and your password that you recived in the previous mail to log in.<br/>Don't forget that by loging in for the first time you are agreeing to the terms and conditions listed in the previous e-mail.<br/><br/>Let the games begin!<br/><br/><br/>Kind regards,<br/><br/>FUJIFILM Nordic<br/>[email protected]"; var user = await UserManager.FindByIdAsync(userId); var mailer = new Mailer(); mailer.Mail(user.UserName, "Welcome to The FUJIFILM Svalbard Challenge!", message); return "Ok"; }