Exemple #1
0
        /// <summary>
        /// 审批代理
        /// </summary>
        public async Task ApprovalAgentAsync(Agent agent)
        {
            var userId = await UserManager.CraeteUser(new CreateUserRequest(agent.Mobile, agent.Email, agent.Mobile, agent.Mobile.Substring(5, 6)));

            agent.Approval(userId);
            await AccountManager.CreateAccountAsync(agent.Id);
        }
        public async Task <IActionResult> CreateAccount(CreateAccountViewModel user)
        {
            var res = await accountManager.CreateAccountAsync(user);

            if (res == null)
            {
                ViewUsersAndRolesViewModel model = new ViewUsersAndRolesViewModel
                {
                    AllUsers = await accountManager.GetAll(),
                    AllRoles = await accountManager.GetAllRoles()
                };
                return(View(nameof(Index), model));
            }
            foreach (var err in res)
            {
                ModelState.AddModelError("", err.Description.ToString());
            }
            return(View(user));
        }
Exemple #3
0
        public async Task <IActionResult> RegisterAsync(string username, string password, string email, string returnUrl)
        {
            var user = new ApplicationUser
            {
                UserName = username,
                Email    = email
            };

            try
            {
                await accountManager.CreateAccountAsync(user, password);
            }
            catch (System.Exception e)
            {
                htmlNotification.SetNotification(HttpContext.Session, "res-fail", e.Message);
                return(RedirectToAction("Register", new { returnUrl }));
            }

            await accountManager.SignInAsync(username, password);

            var url = Url.Action("ConfirmAccount", "Login", new { }, Request.Scheme);

            try
            {
                await accountConfirmatorFactory.CreateCofirmationSender()
                .SendConfirmationEmailAsync(user.Id, url, user.UserName);
            }
            catch (Exception e)
            {
                htmlNotification.SetNotification(HttpContext.Session, "res-fail", $"Confirmation email sending error: {e.Message}");
                return(RedirectToRoute("Home"));
            }

            htmlNotification.SetNotification(HttpContext.Session, "res-suc", "Regirestration success");

            if (string.IsNullOrEmpty(returnUrl))
            {
                return(RedirectToRoute("Home"));
            }

            return(Redirect(returnUrl));
        }
Exemple #4
0
        public async Task <IActionResult> Register([FromBody] Account account, CancellationToken cancellationToken)
        {
            Guard.Argument(account.Email, nameof(account.Email)).NotNull();
            Guard.Argument(account.Password, nameof(account.Password)).NotNull();

            var storageAccount = await _accountManager.CreateAccountAsync(account, cancellationToken);

            if (storageAccount == null)
            {
                throw new Exception("Could not save the account");
            }

            string tokenString = GetAuthToken(storageAccount);

            // return basic user info and authentication token
            return(Ok(new
            {
                account.Email,
                account.Name,
                Token = tokenString
            }));
        }