Пример #1
0
        public ActionResult RegisterUser(RegisterUser newUser)
        {
            if (newUser != null)
            {
                UserAccount user;
                using(AppDb db = new AppDb())
                {
                    if (db.Users.FirstOrDefault(u => u.Email.Equals(newUser.Email)) != null)
                    {
                        //there is already an user with this email address
                        ViewData.ModelState.AddModelError("Email", "Diese E-Mail Adresse wird bereits von einem anderen Spieler genutzt!");
                        return View("register", newUser);
                    }
                    if(!newUser.Password.Equals(newUser.Password2))
                    {
                        //the passwords provieded by the user do not match
                        ViewData.ModelState.AddModelError("Password", "Die angegebenen Passwörter stimmen nicht überein!");
                        return View("register", newUser);
                    }
                    user = new UserAccount()
                    {
                        Admin = false,
                        Picture = "/Content/static/img/unknown_user.png",
                        DisplayName = newUser.Displayname,
                        Email = newUser.Email,
                        LastSeen = DateTime.Now,
                        Registered = DateTime.Now,
                        Enabled = true,
                        Password = GenerateMD5(newUser.Password),
                        Achievements = new LinkedList<Achievement>(),
                        RaceBets = new LinkedList<RaceBet>(),
                        Badges = new LinkedList<Badge>()
                    };
                    db.Users.Add(user);

                    //add player to current season
                    Season currentSeason = db.Seasons.FirstOrDefault(s => s.Year.Equals(DateTime.Now.Year));
                    currentSeason.Players.Add(user);

                    db.SaveChanges();
                }
                //user created successful, redirect to welcome page
                return View("welcome", user);
            }
            return View("register");
        }
Пример #2
0
        public ActionResult Register()
        {
            RegisterUser user = new RegisterUser();

            return View(user);
        }