Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.Email, Email = model.Email
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //TODO //vv I think here is where we add the system Role, and all new should be 'normal' user, we need to find a place to change this role in the near future
                    //ref: http://stackoverflow.com/questions/19689183/add-user-to-role-asp-net-identity
                    var currentUser = UserManager.FindByName(user.UserName);

                    CheckAspRoles();

                    var userRoleResult = UserManager.AddToRole(currentUser.Id, "Normal");

                    await SignInAsync(user, isPersistent : false);

                    ClanUser newClanUser = new ClanUser();

                    newClanUser.name         = model.VillageName;
                    newClanUser.userRoleId   = (short)ClanRole.Member;
                    newClanUser.aspnetUserId = currentUser.Id;

                    ClanUserManager.Insert(newClanUser);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Create(CreateMemberViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ClanUser newMember = new ClanUser();

                    newMember.name       = model.Name;
                    newMember.userRoleId = (short)ClanRole.Member;
                    newMember.clanId     = ClanManager.GetClanId(User.Identity.GetUserId());

                    ClanUserManager.Insert(newMember);
                }
            }
            catch
            {
                return(View(new CreateMemberViewModel()));
            }

            return(RedirectToAction("EditMode"));
        }