public async Task <ActionResult> Register(RegisterViewModel model)
        {
            TurAppEntities Context = new TurAppEntities();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // 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"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public List <MenuAccionVM> GetPermisos(String UserName)
        {
            TurAppEntities      db       = new TurAppEntities();
            List <MenuAccionVM> Permisos = new List <MenuAccionVM>();

            var rolesUser = db.AspNetUsers.FirstOrDefault(r => r.UserName == UserName).AspNetRoles;

            //Recorro todos los Roles asociados al Usuario
            foreach (var rol in rolesUser)
            {
                //Recorro todos los Menus asociados al Rol
                foreach (var menu in rol.MenuAspNetRoles)
                {
                    MenuAccionVM item = new MenuAccionVM();

                    item.menu.ID     = menu.Menu.ID;
                    item.menu.Nombre = menu.Menu.Nombre;

                    //Recorro todas los Acciones asociados al Menu
                    foreach (var accion in menu.MenuAspNetRolesAccion)
                    {
                        item.accion.Add(new Accion
                        {
                            ID     = accion.Accion.ID,
                            Nombre = accion.Accion.Nombre
                        });
                    }

                    Permisos.Add(item);
                }
            }

            return(Permisos);
        }
示例#3
0
        public async Task <ActionResult> Create(RegisterViewModel model)//[Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")]
        {
            TurAppEntities Context = new TurAppEntities();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    return(Json(new { ok = "true" }));
                    //return RedirectToAction("Index", "AspNetUsers");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }