Exemple #1
0
        public async Task <ActionResult> CreateUser(UserCreateView model)
        {
            if (model.ConfirmPassword != model.Password)
            {
                return(View(GetUserView(model)));
            }
            SDHCUser user = Activator.CreateInstance(SDHCUserManager.BaseUser) as SDHCUser;
            var      m    = user.ConvertUserToPost();

            m.Properties = model.Properties;
            var mu = m.ConvertPostToUser(user);

            if (G.UserNameIsNotEmail)
            {
                user.UserName = model.UserName;
            }
            else
            {
                user.UserName = model.Email;
            }
            user.Email = model.Email;
            var result = await userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(View(GetUserView(model)));
            }
            await setRolesForUser(user, model.SelectedRoles);

            return(RedirectToAction("Index", "Roles", new { @area = G.AdminPath }));
        }
Exemple #2
0
        public async Task <IActionResult> Post([FromBody] UserCreateView user)
        {
            string callBack      = Url.Action("Activate", "User", null, Request.Scheme);
            var    userCreateOut = await _service.Create(user, callBack);

            if (userCreateOut is null)
            {
                return(NotFound(new { message = "Invalid username or password." }));
            }

            return(Ok(new { message = userCreateOut.Description }));
        }
Exemple #3
0
        private UserCreateView GetUserView(UserCreateView input = null)
        {
            var user  = Activator.CreateInstance(SDHCUserManager.BaseUser) as SDHCUser;
            var model = new UserCreateView();

            model.Properties = user.ConvertUserToPost().Properties;
            model.Roles      = getRoleAndUsers();
            if (input != null)
            {
                model.Properties = input.Properties;
            }
            return(model);
        }
Exemple #4
0
        public async Task <ActionResult> EditUser(string id)
        {
            var user = await userManager.FindByIdAsync(id);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }
            var userPass = user.ConvertUserToPost();
            var model    = new UserCreateView();

            model.Properties    = userPass.Properties;
            model.Id            = user.Id;
            model.UserName      = user.UserName;
            model.Email         = user.Email;
            model.Roles         = getRoleAndUsers();
            model.SelectedRoles = user.Roles.Select(b => b.RoleId).ToList();
            return(View(model));
        }
        /// <summary>
        /// Gera uma nova conta de usuário.
        /// E envia email de confirmação.
        /// </summary>
        /// <param name="userCreate"></param>
        /// <param name="callback"></param>
        /// <returns>O resultado do comando.</returns>
        public async Task <UserCreateOutView> Create(UserCreateView userCreate, string callback)
        {
            User user = _mapper.Map <User>(userCreate);

            IdentityResult result = await _userManager.CreateAsync(user, userCreate.Password);

            if (!result.Succeeded)
            {
                return(new UserCreateOutView(400, result.ToString()));
            }

            var token = await CreateTokenEmailConfirmation(user);

            string bodyMessage =
                CreateBodyEmail(Messages.AccountEmailActivation, user.FullName, callback, user.Email, token);

            await _emailService.SendEmailAsync(user.FullName, user.Email, "Account activation.", bodyMessage);

            return(new UserCreateOutView(201, "Waiting for activation."));
        }
Exemple #6
0
        public async Task <ActionResult> EditUser(UserCreateView model)
        {
            var user = await userManager.FindByIdAsync(model.Id);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                var passModel = user.ConvertUserToPost();
                passModel.Properties = model.Properties;

                passModel.ConvertPostToUser(user);
                await userManager.UpdateAsync(user);
                await setRolesForUser(user, model.SelectedRoles);
            }
            catch { }

            return(RedirectToAction("Index"));
        }