Example #1
0
        // TODO extract in another service ?
        private async Task SendEmalForNewUser(User user)
        {
            await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

            UriBuilder url = new UriBuilder(callbackUrl);
            url.Port = -1;
            callbackUrl = url.Uri.ToString();

            await UserManager.SendEmailAsync(user.Id, "Потвърждаване на имейл.", "Моля потвърдете вашият имейл като натиснете <a href=\"" + callbackUrl + "\">тук.</a>");
        }
Example #2
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return this.RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await this.AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return this.View("ExternalLoginFailure");
                }

                var user = new User
                {
                    UserName = model.Email,
                    Email = model.Email
                };

                var result = await this.UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await this.UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return this.RedirectToLocal(returnUrl);
                    }
                }

                this.AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return this.View(model);
        }
Example #3
0
        // TODO extract in another service ?
        private async Task SendEmailForForgotPassword(User user)
        {
            string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

            UriBuilder url = new UriBuilder(callbackUrl);
            url.Port = -1;
            callbackUrl = url.Uri.ToString();

            await UserManager.SendEmailAsync(user.Id, "Забравена парола.", "Въведете новата парола като натиснете: <a href=\"" + callbackUrl + "\">тук.</a>");
        }
Example #4
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {                
                var user = new User
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FN = model.FacultyNumber,
                    FirstName = model.FirstName,
                    LastName = model.LastName
                };

                var result = await this.UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await this.SendEmalForNewUser(user);

                    this.AddNotification("Проверете имейлът си за да активирате акаунта.", NotificationType.WARNING);

                    return this.RedirectToAction<AccountController>(c => c.Login(string.Empty));
                }

                this.AddErrors(result);
            }
            
            return this.View(model);
        }