예제 #1
0
 public ChattyProfile(ChattyUser chattyUser, string description, string location,
     string pic, string steamId, string psnId, string xboxId)
 {
     ChattyUser = chattyUser;
     Description = description;
     Location = location;
     Pic = pic;
     SteamId = steamId;
     PsnId = psnId;
     XboxId = xboxId;
 }
        public ActionResult Login(ChattyLoginViewModel viewModel)
        {
            var chattyUser = _db.ChattyUsers.SingleOrDefault(u => u.ShackName.Equals(viewModel.Username));
            // Must be a new signup.
            if (chattyUser == null) {
                chattyUser = new ChattyUser();
            }

            // We could skip verifying user is they're already in our database,
            // but maybe they became a moderator since originally registering?
            // Or closed their shacknews account?
            // Or recently became a ten year member?
            // Either way, go through the steps of verifying and updating chatty user.

            var isModerator = false;
            if (VerifyUser(viewModel.Username, viewModel.Password, out isModerator)) {
                chattyUser = chattyUser.Id == 0
                    ? new ChattyUser(viewModel.Username, isModerator)
                    : chattyUser;
                chattyUser.IsTenYearMember = IsTenYearMember(chattyUser.ShackName);
                // Let's update the user, since their ten year or mod status could
                // have changed.
                if (chattyUser.Id != 0) {
                    _db.Entry(chattyUser).State = EntityState.Modified;
                    _db.SaveChanges();
                }
            } else {
                ModelState.AddModelError("Error", "Sorry! You must be a registered user of Shacknews.com to create a profile.");

                return View();
            }
            // Don't save the ChattyUser just yet. Let's make sure they create a profile first.
            TempData["chattyUser"] = chattyUser;

            return RedirectToAction("Create", "ChattyProfile", new { userId = viewModel.Username });
        }