public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { if (model.Email.EndsWith("@accruent.com")) { var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { Player myPlayer = new Player(); myPlayer.LoginName = model.Email; myPlayer.Password = model.Password; myPlayer.FirstName = model.FirstName; myPlayer.LastName = model.LastName; myPlayer.CurrentEloRating = 1500; myPlayer.Department = model.Department; myPlayer.Active = true; myPlayer.IsAdmin = false; PlayerService.CreateNewPlayer(myPlayer); await SignInAsync(user, isPersistent: false); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); SmtpClient myClient = new SmtpClient("smtp.gmail.com", 587); myClient.UseDefaultCredentials = false; myClient.EnableSsl = true; myClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "ClintIsASillyWabbit"); string to = user.Email; string from = "*****@*****.**"; string subject = "WELCOME TO STAPPPPP"; string body = "Welcome to STAPPPP. The world is now your oyster, and the ping-pong paddle is your oyster-opening knife. Please confirm your account by visiting this URL: " + callbackUrl; MailMessage message = new MailMessage(from, to, subject, body); myClient.Send(message); myClient.Dispose(); return RedirectToAction("Index", "Home"); } else { AddErrors(result); } } else { ModelState.AddModelError("", "Please use an @accruent.com email account."); } } // If we got this far, something failed, redisplay form return View(model); }
/// <summary> /// Returns Player's first and last name /// </summary> /// <returns></returns> private static string GetFullName(Player player) { var fullname = string.Format("{0} {1}", player.FirstName, player.LastName); //NOTE: This method is currently not used in anywhere return fullname; }
/// <summary> /// Determines if user's password is correct /// </summary> /// <param name="password">User's input password</param> /// <returns>True or false</returns> public static bool IsPasswordCorrect(Player player, string password) { return (player.Password == password ? true : false); }
/// <summary> /// Deletes an existing Player /// </summary> public static void DeleteExistingPlayer(Player player) { IPingPongRepository<Player> _repo = new PingPongRepository<Player>(); _repo.Delete(player.PlayerId); }
/// <summary> /// Updates an existing Player /// </summary> public static void UpdateExistingPlayer(Player player) { IPingPongRepository<Player> _repo = new PingPongRepository<Player>(); _repo.Update(player); }
/// <summary> /// Creates a new Player /// </summary> public static void CreateNewPlayer(Player player) { IPingPongRepository<Player> _repo = new PingPongRepository<Player>(); _repo.Create(player); }