コード例 #1
0
ファイル: UserMailer.cs プロジェクト: alebustillo/SciReview
        public virtual MvcMailMessage ConfirmEmail(AppMember user, string callbackUrl)
        {
            var model = new EmailModel();
            model.UserFirstName = user.FirstName;
            model.CallbackUrl = callbackUrl;

            ViewData.Model = model;

            return Populate(m =>
            {
                m.Subject = "Confirme su correo electrónico.";
                m.ViewName = "ConfirmEmail";
                m.From = new MailAddress("*****@*****.**", "SciReview");
                m.To.Add(user.Email);
                m.IsBodyHtml = true;
            });
        }
コード例 #2
0
ファイル: UserMailer.cs プロジェクト: alebustillo/SciReview
        public virtual MvcMailMessage PasswordReset(AppMember user, string callbackUrl)
        {
            var model = new EmailModel();
            model.UserFirstName = user.FirstName;
            model.CallbackUrl = callbackUrl;

            ViewData.Model = model;

            return Populate(m =>
            {
                m.Subject = "Solicitud para recuperar contraseña";
                m.ViewName = "PasswordReset";
                m.From = new MailAddress("*****@*****.**", "SciReview");
                m.To.Add(user.Email);
                m.IsBodyHtml = true;
            });
        }
コード例 #3
0
 private async Task SignInAsync(AppMember AppMember, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await AppMember.GenerateUserIdentityAsync(UserManager));
 }
コード例 #4
0
        public async Task<ActionResult> AddUser(UserViewModel model)
        {
            if (SiteConfiguration.IsDemoMode)
            {
                DisplayMessage("You can't save changes in demo mode.", MessageType.Warning);
                return RedirectToAction("AddUser");
            }

            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(model.NewPassword))
                {
                    AddError("NewPassword", "Escriba una contraseña para el usuario.");
                    return RedirectToAction("AddUser");
                }

                var usedEmail = await userManager.FindByEmailAsync(model.Email);
                if (usedEmail == null)
                {
                    var user = new AppMember
                    {
                        City = model.City,
                        CountryID = model.CountryID,
                        CreationDateUtc = DateTime.Now,
                        DegreeID = model.DegreeID,
                        Email = model.Email,
                        FirstName = model.FirstName,
                        Gender = model.Gender,
                        LastName = model.LastName,
                        PhoneNumber = model.PhoneNumber,
                        PictureUrl = "/img/profiles/default.png",
                        UserName = model.Email
                    };

                    var create = await userManager.CreateAsync(user, model.NewPassword);
                    if (create.Succeeded)
                    {
                        user = await userManager.FindByEmailAsync(model.Email);
                        var role = paramService.GetAllRoles().Where(x => x.RoleID == model.Role.RoleID).First();
                        await userManager.AddToRoleAsync(user.UserID, role.Name);

                        DisplayMessage("Se creó el usuario " + role.Name + " \"" + user.FullName + "\".", MessageType.OK);
                        return RedirectToAction("Users");
                    }
                    else
                        AddError("Ha ocurrido un error al crear el usuario. Por favor intente de nuevo.");
                }
                else
                    AddError("Email", "Ya existe un usuario registrado con el correo electrónico especificado.");
            }

            return RedirectToAction("AddUser");
        }
コード例 #5
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToRole();

            if (ModelState.IsValid)
            {
                var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (loginInfo == null)
                    return View("ExternalLoginFailure");

                string pictureUrl = "/img/profiles/default.png";
                char? gender = null;
                string genderValue = loginInfo.ExternalIdentity.FindFirstValue(ClaimTypes.Gender);
                if (genderValue != null)
                    gender = genderValue.First();

                if (loginInfo.Login.LoginProvider == "Google")
                {
                    string url = loginInfo.ExternalIdentity.FindFirstValue("picture");
                    if (!string.IsNullOrEmpty(url))
                        pictureUrl = HtmlHelpers.ResizeGoogleProfilePicture(url, 200);
                }
                else if(loginInfo.Login.LoginProvider == "Facebook")
                {
                    var profileId = loginInfo.ExternalIdentity.FindFirstValue(ClaimTypes.NameIdentifier);
                    if (profileId != null)
                        pictureUrl = string.Format("https://graph.facebook.com/{0}/picture?width=200&height=200", profileId);
                }

                var AppMember = new AppMember {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    PictureUrl = pictureUrl,
                    Gender = gender
                };

                var result = await userManager.CreateAsync(AppMember);

                if (result.Succeeded)
                {
                    result = await userManager.AddLoginAsync(AppMember.Id, loginInfo.Login);
                    if (result.Succeeded)
                    {
                        await userManager.AddToRoleAsync(AppMember.Id, "Autor");
                        await signInManager.SignInAsync(AppMember, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(model.ReturnUrl);
                    }
                }

                AddError("Email", Translations.Account.AlreadyRegisteredAccount);
            }

            return View(model);
        }
コード例 #6
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var appMember = new AppMember
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    PictureUrl = "/img/profiles/default.png"
                };

                var result = await userManager.CreateAsync(appMember, model.Password);
                
                if (result.Succeeded)
                {
                    var currentUser = await userManager.FindByNameAsync(model.Email);
                    await userManager.AddToRoleAsync(currentUser.Id, "Autor");
                    //await signInManager.SignInAsync(currentUser, isPersistent: false, rememberBrowser: false);

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

                    var mailer = new UserMailer();
                    mailer.ConfirmEmail(currentUser, callbackUrl).Send();
                    ViewBag.Email = currentUser.Email;
                    return View("CheckEmail");
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #7
0
        public void AddCurrentUserAsAuthor(AppMember currentUser)
        {
            if (AuthorList == null || !AuthorList.Any() || currentUser == null)
                return;

            AuthorList[0].FirstName = currentUser.FirstName;
            AuthorList[0].LastName = currentUser.LastName;
            AuthorList[0].Email = currentUser.Email;
            AuthorList[0].DegreeID = currentUser.DegreeID.HasValue ? currentUser.DegreeID.Value : 0;
            AuthorList[0].IsVisible = true;
        }