//
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(userId);

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                IoTConnectionString = currentUser.IoTHubConnectionString,
                IoTHubEndpoint = currentUser.IoTHubEndpoint,
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }
Esempio n. 2
0
        public async Task <ActionResult> Disassociate(string loginProvider, string providerKey)
        {
            ManageMessageId message = ManageMessageId.LoginNotFound;
            var             logins  = await UserManager.GetLoginsAsync(User.Identity.GetUserId());

            var userLogin = logins.FirstOrDefault(x => x.LoginProvider == loginProvider && x.ProviderKey == providerKey);

            if (userLogin != null)
            {
                IdentityResult result = await UserManager.RemoveLoginAsync(User.Identity.GetUserId(), userLogin);

                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
                    await SignInAsync(user, isPersistent : false);

                    message = ManageMessageId.RemoveLoginSuccess;
                }
                else
                {
                    message = ManageMessageId.Error;
                }
            }
            return(RedirectToAction("Manage", new { Message = message }));
        }
Esempio n. 3
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var user = UserManager.FindById(User.Identity.GetUserId());
            var userAvatar = user.UserPhotos.FirstOrDefault(p => p.IsUserAvatar);

            var model = new IndexViewModel
            {
                AvatarSrc = userAvatar != null ? userAvatar.BlobStorageLink : "",
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }
Esempio n. 4
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());

            // lambda to extract photolist using currentUser as filter
            var photoList = Db.Photos.Where(x => x.UserId == userId).ToList();
            var model = new IndexViewModel
            {
                PhotoList = photoList,
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            ViewBag.User = currentUser;
            return View(model);
        }
        public async Task <ActionResult> New(IndexViewModel model)
        {
            ManageMessageId message = ManageMessageId.Error;

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", new { Message = message }));
            }
            ApplicationUser currentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            currentUser.AddressLine1 = model.AddressLine1;
            currentUser.AddressLine2 = model.AddressLine2;
            currentUser.Country      = model.Country;
            currentUser.City         = model.City;
            currentUser.ZipCode      = model.ZipCode;
            var result = await UserManager.UpdateAsync(currentUser);

            if (result.Succeeded)
            {
                message = ManageMessageId.UpdateUserDetailsSuccess;
            }
            else
            {
                message = ManageMessageId.Error;
            }
            return(RedirectToAction("Index", new { Message = message }));
        }
Esempio n. 6
0
        public async Task<IActionResult> Index(ManageMessageId? message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var user = await GetCurrentUserAsync();
            if (user == null)
            {
                return View("Error");
            }
            var model = new IndexViewModel
            {
                HasPassword = await _userManager.HasPasswordAsync(user),
                PhoneNumber = await _userManager.GetPhoneNumberAsync(user),
                TwoFactor = await _userManager.GetTwoFactorEnabledAsync(user),
                Logins = await _userManager.GetLoginsAsync(user),
                BrowserRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user)
            };
            return View(model);
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                //HasCV = repo.GetSpecificUser(userId).CV != null ? true : false
                CV = repo.GetSpecificUser(userId).CV != null ? repo.GetSpecificUser(userId).CV : null
            };

            ViewBag.userId = userId;

            return View(model);
        }
Esempio n. 8
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            var tickets = from ticket in db.Tickets
                          select ticket;

            tickets = tickets.Where(x => x.OwnerLogin == User.Identity.Name && x.DateFrom > DateTime.Now);

            var user = MyUserManager.FindById(User.Identity.GetUserId());

            var viewModel = new IndexViewModel();
            viewModel.UserMoney = user.UserMoney;
            viewModel.UserTickets = tickets.ToList();

            return View(viewModel);
        }
Esempio n. 9
0
        //
        // GET: /Manage/Index
        //public ActionResult Index()
        //{
        //    var userId = getGuid(User.Identity.GetUserId());
        //    var model = _userManager.FindById(userId);

        //   // var model = new IndexViewModel();

        //    return View(model);
        //}

        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : message == ManageMessageId.ChangeEmailSuccess ? "Your Email was changed."
                : message == ManageMessageId.ChangeNumberSuccess ? "Your phone number was changed."
                : message == ManageMessageId.ChangeInfoSuccess ? "Your information was changed."
                : "";

            var userId = getGuid(User.Identity.GetUserId());
            var user = _userManager.FindById(userId);

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                //PhoneNumber = await _userManager.GetPhoneNumberAsync(userId),
                //TwoFactor = await _userManager.GetTwoFactorEnabledAsync(userId),
                Logins = await _userManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId.ToString())
                //MyCustomField = user.MyCustomField
            };
            model.ChangeCityModel = user.City;
            model.ChangeNameModel = user.Name;
            model.ChangeLastNameModel = user.LastName;
            return View(model);
        }
        //
        // GET: /Account/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two factor provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "The phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(User.Identity.GetUserId()),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(User.Identity.GetUserId()),
                Logins = await UserManager.GetLoginsAsync(User.Identity.GetUserId()),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(User.Identity.GetUserId())
            };

            // check if display cancel option
            if(hasSubscription() == true)
                ViewData["hasSubscription"] = true;
            else
                ViewData["hasSubscription"] = false;

            return View(model);
        }
Esempio n. 11
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var user = UserManager.Users.Where(_ => _.Id == userId).FirstOrDefault();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                City = user.City,
                FirstName = user.FirstName,
                LastName = user.LastName,
                StreetAndNumber = user.StreetAndNumber,
                ZipCode = user.ZipCode
            };
            return View(model);
        }
        /// <summary>
        ///     Display UserProfile management view
        /// </summary>
        /// <param name="message">message about changes in account settings</param>
        /// <returns></returns>
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess
                    ? ManageResource.PasswordChanged
                    : message == ManageMessageId.SetPasswordSuccess
                        ? ManageResource.PasswordSet
                        : message == ManageMessageId.SetTwoFactorSuccess
                            ? ManageResource.TwoFactorAuthProviderSet
                            : message == ManageMessageId.Error
                                ? ManageResource.ErrorOccured
                                : message == ManageMessageId.AddPhoneSuccess
                                    ? ManageResource.PhoneNumberAdded
                                    : message == ManageMessageId.RemovePhoneSuccess
                                        ? ManageResource.PhoneNumberRemoved
                                        : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = this.HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return this.View(model);
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            // DRM Changed -- all occurences in this file
            //TODO: need better implementation of this to avoif the X.Parse junk...
            //x var userId = User.Identity.GetUserId();
            var userId = Guid.Parse(User.Identity.GetUserId());
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                // DRM Changed
                //x BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId.ToString())
            };

            var context = HttpContext.GetOwinContext().Get<ApplicationDbContext>();
            model.UserId = context.CurrentUserId;
            model.UserName = context.CurrentUserName;

            return View(model);
        }
        // GET: Account/Settings
        public ActionResult Index(ManageMessageId? message)
        {
            ViewBag.SubTitle = "Settings";

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.ChangeUsernameSuccess ? "Your username has been changed."
                : message == ManageMessageId.ChangeEmailSuccess ? "Your email has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            if(message == ManageMessageId.Error)
            {
                ViewBag.StatusClass = "alert-danger";
            }
            else
            {
                ViewBag.StatusClass = "alert-success";
            }
            
            return View();
        }
Esempio n. 15
0
        // GET: Return
        public ActionResult Retrieve(ManageMessageId? message, int? page)
        {
            try
            {
                var records = db.Returns.ToList();
                if (records == null)
                {
                    return RedirectToAction("Index", "Admin", new { message = ManageMessageId.Error });
                }

                ViewBag.StatusMessage =
                message == ManageMessageId.UpdateSuccess ? "You have successfully updated a Item."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";

                //Paging Section
                var pageNumber = page ?? 1; // if no pagenumber is specified in the querystring, it will assign pageNumber to 1 by default
                var pageOfProducts = records.ToPagedList(pageNumber, 10); //set the number of records per page
                ViewBag.pageOfProducts = pageOfProducts;

                GetNewSupplierActivation();
                GetNewModelsActivation();
                return View();
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Esempio n. 16
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                MinutesBetweenAlerts = db.Users.Single(m => m.UserName == User.Identity.Name).MinutesBetweenAlerts,
            };

            return View(model);
        }
Esempio n. 17
0
        // GET: Account/Email
        public ActionResult Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.SentConfirmationEmail ? "Confirmation email has been sent to your email address."
                : message == ManageMessageId.ConfirmedEmailSuccess ? "Your email has been confirmed."
                : message == ManageMessageId.ChangeEmailSuccess ? "Your email has been changed."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";

            if (message == ManageMessageId.Error)
            {
                ViewBag.StatusClass = "alert-danger";
            }
            else
            {
                ViewBag.StatusClass = "alert-success";
            }

            var user = UserManager.FindById(User.Identity.GetUserId<int>());

            EmailViewModel model = new EmailViewModel
            {
                EmailAddress = user.Email,
                EmailConfirmed = user.EmailConfirmed
            };

            return View(model);
        }
Esempio n. 18
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "パスワードが変更されました。"
                : message == ManageMessageId.SetPasswordSuccess ? "パスワードが設定されました。"
                : message == ManageMessageId.SetTwoFactorSuccess ? "2 要素認証プロバイダーが設定されました。"
                : message == ManageMessageId.Error ? "エラーが発生しました。"
                : message == ManageMessageId.AddPhoneSuccess ? "電話番号が追加されました。"
                : message == ManageMessageId.RemovePhoneSuccess ? "電話番号が削除されました。"
                : "";

            var userId = User.Identity.GetUserId();
            var user = await GetApplicationUser();
            if (user == null)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                User = user
            };
            return View(model);
        }
Esempio n. 19
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Votre mot de passe a été changé."
                : message == ManageMessageId.SetPasswordSuccess ? "Votre mot de passe a été défini."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Votre fournisseur d'authentification à 2 facteurs a été défini."
                : message == ManageMessageId.Error ? "Une erreur s'est produite."
                : message == ManageMessageId.AddPhoneSuccess ? "Votre numéro de téléphone a été ajouté."
                : message == ManageMessageId.RemovePhoneSuccess ? "Votre numéro de téléphone a été supprimé."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                Nom = UserManager.Users.First(x => x.Id == userId).Nom,
                Prenom = UserManager.Users.First(x => x.Id == userId).Prenom,
                Points = UserManager.Users.First(x => x.Id == userId).Points
            };
            return View(model);
        }
Esempio n. 20
0
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            this.ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess
                                             ? "Your password has been changed."
                                             : message == ManageMessageId.SetPasswordSuccess
                                                   ? "Your password has been set."
                                                   : message == ManageMessageId.SetTwoFactorSuccess
                                                         ? "Your two-factor authentication provider has been set."
                                                         : message == ManageMessageId.Error
                                                               ? "An error has occurred."
                                                               : message == ManageMessageId.AddPhoneSuccess
                                                                     ? "Your phone number was added."
                                                                     : message == ManageMessageId.RemovePhoneSuccess
                                                                           ? "Your phone number was removed."
                                                                           : string.Empty;

            var userId = this.User.Identity.GetUserId();
            var user = this.UserManager.FindById(userId);
            var model = new IndexViewModel
            {
                PhotoUrl = user.ProfilePhotoUrl,

                HasPassword = this.HasPassword(),
                PhoneNumber = await this.UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await this.UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await this.UserManager.GetLoginsAsync(userId),
                BrowserRemembered =
                                    await
                                    this.AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return this.View(model);
        }
Esempio n. 21
0
        public async Task<IActionResult> Index(ManageMessageId? message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var user = GetCurrentUser();
            var model = new IndexViewModel
            {
                HasPassword = await _userManager.HasPasswordAsync(user),
                EmailAddress = user.Email,
                IsEmailAddressConfirmed = user.EmailConfirmed,
                PhoneNumber = await _userManager.GetPhoneNumberAsync(user),
                TwoFactor = await _userManager.GetTwoFactorEnabledAsync(user),
                Logins = await _userManager.GetLoginsAsync(user),
                BrowserRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user),
                AssociatedSkills = user.AssociatedSkills,
                TimeZoneId = user.TimeZoneId,
                Name = user.Name
            };
            return View(model);
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            // Added this code, so that a user can see their claims

            var claims = new List<string>();

            var user = User as ClaimsPrincipal;
            foreach (var claim in user.Claims)
            {
                claims.Add(string.Format("{0} | {1} | {2}", claim.Issuer, claim.Type, claim.Value));
            }

            ViewBag.Claims = claims;
            return View(model);
        }
Esempio n. 23
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Ваш пароль изменен."
                : message == ManageMessageId.SetPasswordSuccess ? "Пароль задан."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Настроен поставщик двухфакторной проверки подлинности."
                : message == ManageMessageId.Error ? "Произошла ошибка."
                : message == ManageMessageId.AddPhoneSuccess ? "Ваш номер телефона добавлен."
                : message == ManageMessageId.RemovePhoneSuccess ? "Ваш номер телефона удален."
                : "";

            var userId = User.Identity.GetUserId();
            ApplicationUser us = db.Users.Where(x => x.Id == userId).First();
            ViewBag.User = us;
            ViewBag.Photo = us.Photo;
           
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            return View(model);
            
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : message == ManageMessageId.ChangeTelephoneSuccess ? "Číslo bylo úspěšně změněno."
                : message == ManageMessageId.ChangeMailSuccess ? "E-mail byl úspěšně změněn."
                : "";

            var userId = User.Identity.GetUserId();
            var user = await UserManager.FindByIdAsync(userId);
            var model = new IndexViewModel
            {
                //HasPassword = HasPassword(),
                //PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                //TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                //Logins = await UserManager.GetLoginsAsync(userId),
                //BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
                Telephone = user.Telephone,
                Email = user.Email
            };
            return View(model);
        }
Esempio n. 25
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess
                    ? "已更改你的密码。"
                    : message == ManageMessageId.SetPasswordSuccess
                        ? "已设置你的密码。"
                        : message == ManageMessageId.SetTwoFactorSuccess
                            ? "已设置你的双重身份验证提供程序。"
                            : message == ManageMessageId.Error
                                ? "出现错误。"
                                : message == ManageMessageId.AddPhoneSuccess
                                    ? "已添加你的电话号码。"
                                    : message == ManageMessageId.RemovePhoneSuccess
                                        ? "已删除你的电话号码。"
                                        : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var user = UserManager.FindById(userId); // Here we grab the logged in users information.
            var model = new IndexViewModel
            {
                FirstName = user.FirstName,
                MiddleName = user.MiddleName,
                LastName = user.LastName,
                Gender = user.Gender,
                Address = user.Address,
                Postcode = user.Postcode,
                Card = user.Card, // Security issue? Not that it matters
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }
Esempio n. 27
0
 //public async Task<ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
 public ActionResult AddPhoneNumber(AddPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     using (BlogDbContext db = new BlogDbContext())
     {
         ApplicationUser user = db.Users.Where(u => u.UserName == User.Identity.Name).First();
         db.Users.Attach(user);
         ManageMessageId statusMsg = ManageMessageId.AddPhoneSuccess;
         if (user.PhoneNumber != null)
         {
             statusMsg = ManageMessageId.ChangePhoneSuccess;
         }
         user.PhoneNumber = model.Number;
         db.SaveChanges();
         return(RedirectToAction("Index", "Manage", new { Message = statusMsg }));
     }
     // Generate the token and send it
     //var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);
     //if (UserManager.SmsService != null)
     //{
     //    var message = new IdentityMessage
     //    {
     //        Destination = model.Number,
     //        Body = "Your security code is: " + code
     //    };
     //    await UserManager.SmsService.SendAsync(message);
     //}
     //return RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number });
 }
Esempio n. 28
0
        //
        // GET: /Account/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {

            if (User.Identity.Name.Equals("*****@*****.**"))
                return RedirectToAction("GuestIndex");

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two factor provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "The phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(User.Identity.GetUserId()),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(User.Identity.GetUserId()),
                Logins = await UserManager.GetLoginsAsync(User.Identity.GetUserId()),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(User.Identity.GetUserId())
            };
            return View(model);
        }
        public ActionResult Index(ManageMessageId? message)
        {
            var userId = User.Identity.GetUserId();

            var model = this.Mapper.Map<UserViewModel>(this.usersService.GetById(userId));
            return this.View(model);
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var user = this.Data.Users.All().FirstOrDefault(u => u.Id == userId);
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                Address = user.Address,
                Bio = user.Bio,
                FamilyName = user.FamilyName,
                Joined = user.Joined,
                Name = user.Name
            };
            return View(model);
        }
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : message == ManageMessageId.PhotoUploadSuccess ? "Your photo has been uploaded"
                : message == ManageMessageId.FileExtensionError ? "Only jpg, png, and gif file formats are allowed."
                : "";

            var userId = User.Identity.GetUserId();

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }
Esempio n. 32
0
    //
    // GET: /Manage/Index
    public async Task<ActionResult> Index(ManageMessageId? message)
    {
      ViewBag.StatusMessage =
        message == ManageMessageId.ChangePasswordSuccess
          ? "Your password has been changed."
          : message == ManageMessageId.SetPasswordSuccess
            ? "Your password has been set."
            : message == ManageMessageId.SetTwoFactorSuccess
              ? "Your two-factor authentication provider has been set."
              : message == ManageMessageId.Error
                ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess
                  ? "Your phone number was added."
                  : message == ManageMessageId.RemovePhoneSuccess
                    ? "Your phone number was removed."
                    : "";

      var userId = User.Identity.GetUserId();
      var model = new IndexViewModel
      {
        HasPassword = HasPassword(),
        PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
        TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
        Logins = await UserManager.GetLoginsAsync(userId),
        BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
        ManageUnicornViews = _unicornCampaign.UnicornManagePartialView
      };
      return View(model);
    }
        public ActionResult Index(ManageMessageId? message)
        {
            if (message != null)
            {
                TempData["Alert"] =
                message == ManageMessageId.Error ? "出现错误。"
                : message == ManageMessageId.AddEducationSuccess ? "已添加你的一条教育经历。"
                : message == ManageMessageId.AddWorkSuccess ? "已添加一条你的工作经历。"
                : message == ManageMessageId.ChangePasswordSuccess ? "修改密码成功。"
                : message == ManageMessageId.AcessDenied ? "你没有权限进行这项操作。"
                : message == ManageMessageId.ApplySuccess ? "申请加入成功,请等待团队管理员审批。"
                : message == ManageMessageId.ProjectSuccess ? "项目申请成功,请等待管理员审批。"
                : message == ManageMessageId.RecruitSuccess ? "招募请求发送成功,请等待该用户响应。"
                : message == ManageMessageId.UpdateUserProfileSuccess ? "修改个人信息成功。"
                : message == ManageMessageId.OperationSuccess ? "操作成功。"
                : message == ManageMessageId.AdminQuit ? "作为团队创始人你无法将自己从团队中删除。"
                : message == ManageMessageId.ApproveSuccess ? "成员列表审核成功!"
                : message == ManageMessageId.UserIdentitySuccess ? "申请实名认证成功,请等待管理员审批!"
                : "";
            }

            var user = Extensions.GetContextUser(ref db);
            var model = new ManageIndexViewModel
            {
                NewMessage = user.Messages.Where(m => m.Time >= DateTime.Now.AddMonths(-3)).OrderByDescending(m => m.Time).ToList()
            };
            return View(model);
        }
Esempio n. 34
0
 RedirectToManager(ManageMessageId message)
 {
     StateController.Navigate(
         "Manage",
         new NavigationData
     {
         { "message", message }
     });
 }
Esempio n. 35
0
        public async Task <ActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            ManageMessageId message = await _manageUsersService.SetPassword(User.Identity.GetUserId(), model.NewPassword);

            return(RedirectToAction("Index", new { Message = message }));
        }
Esempio n. 36
0
 public ActionResult Manage(ManageMessageId message)
 {
     //ViewBag.StatusMessage =
     // message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
     // : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
     //: message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
     //: message == ManageMessageId.Error ? "An error has occurred."
     //: "";
     //ViewBag.HasLocalPassword = HasPassword();
     //ViewBag.ReturnUrl = Url.Action("Manage");
     return(RedirectToAction("Index", "Home"));
 }
        public void Index_ShouldDisplayMessage(ManageMessageId messageId, string expected)
        {
            // Arrange
            var signInManagerMock = new Mock <IApplicationSignInManager>();
            var userManagerMock   = new Mock <IApplicationUserManager>();

            var controller = new ManageController(userManagerMock.Object, signInManagerMock.Object);

            // Act
            var result = controller.Index(messageId);

            // Assert
            StringAssert.Contains(expected, controller.ViewBag.StatusMessage);
        }
 public ActionResult TambahBonus(string bulanBekerja, string bulanDibayar,
                                 string tahunDibayar, string bulanBekerjaHingga, string Command)
 {
     if (Command == "Tambah")
     {
         //TODO add to HR_BONUS_SAMBILAN_DETAIL
         ManageMessageId outputMsg = ManageMessageId.Tambah;
         HR_BONUS_SAMBILAN_DETAIL.UpdateTambahBonus();
         return(RedirectToAction("UrusBonus", "PengurusanKakitanganSambilan",
                                 new { month = bulanDibayar, tahunbekerja = tahunDibayar, message = outputMsg }));
     }
     else if (Command == "Batal")
     {
         HR_BONUS_SAMBILAN_DETAIL.DeleteTambahBonus();
         return(RedirectToAction("TambahBonus",
                                 new { month = bulanDibayar, year = tahunDibayar }));
     }
     else //preview ("Pratonton")
     {
         List <BonusSambilanDetailModel> bonus = new List <BonusSambilanDetailModel>();
         ViewBag.MinBulan   = 0;
         ViewBag.MaxBulan   = 0;
         ViewBag.MaxTahun   = 0;
         ViewBag.BulanBonus = 0;
         try
         {
             int startMonth = Convert.ToInt32(bulanBekerja);
             int endMonth   = Convert.ToInt32(bulanBekerjaHingga);
             int month      = Convert.ToInt32(bulanDibayar);
             int year       = Convert.ToInt32(tahunDibayar);
             ViewBag.MinBulan   = startMonth;
             ViewBag.MaxBulan   = endMonth;
             ViewBag.BulanBonus = month;
             ViewBag.MaxTahun   = year;
             bonus = BonusSambilanDetailModel.GetDetailsFromTransaksi(startMonth, month, year, endMonth);
             if (bonus.Count() > 0)
             {
                 HR_BONUS_SAMBILAN_DETAIL.InsertTambahBonus(bonus); //add to database
             }
         }
         catch (Exception ex)
         {
             Console.Write(ex.ToString());
         }
         return(View(bonus));
     }
 }
Esempio n. 39
0
        public async Task <ActionResult> LinkLoginCallback()
        {
            ApplicationUser user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }
            ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync(await _userManager.GetUserIdAsync(user));

            if (info == null)
            {
                return(RedirectToAction(nameof(ManageLogins), new { Message = ManageMessageId.Error }));
            }
            IdentityResult result = await _userManager.AddLoginAsync(user, info);

            ManageMessageId message = result.Succeeded ? ManageMessageId.AddLoginSuccess : ManageMessageId.Error;

            return(RedirectToAction(nameof(ManageLogins), new { Message = message }));
        }
Esempio n. 40
0
        public ActionResult GetFacebookUserInfor()
        {
            try
            {
                FacebookUserInfor fb       = new ClassEngine.FacebookUserInfor();
                var               userId   = User.Identity.GetUserId();
                AspNetUser        user     = db.AspNetUsers.SingleOrDefault(t => t.Id == userId);
                FBUserInforReturn datauser = fb.getEmail(user.AspNetUserLogins.SingleOrDefault(t => t.LoginProvider == "Facebook").ProviderKey);

                user.profile_avatar_link = datauser.picture;
                user.hoTen = datauser.name;

                db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                ManageMessageId message = new ManageMessageId();
                message = ManageMessageId.Error;
                return(RedirectToAction("Index", message));
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 41
0
 private void AddMessage(ManageMessageId message)
 {
     ViewData["Message"] = _localizer[Convert.ToString("message")];
 }
        public async Task <ActionResult> ChangeProfile(ApplicationUser applicationUser)
        {
            ManageMessageId manageMessageId = ManageMessageId.Error;

            var retrievedUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            retrievedUser.FirstName = applicationUser.FirstName;
            retrievedUser.LastName  = applicationUser.LastName;
            retrievedUser.Address   = applicationUser.Address;
            retrievedUser.City      = applicationUser.City;
            retrievedUser.State     = applicationUser.State;
            retrievedUser.ZipCode   = applicationUser.ZipCode;

            // Update User Profile
            var result = await UserManager.UpdateAsync(retrievedUser);

            if (result.Succeeded)
            {
                manageMessageId = ManageMessageId.ChangeProfileSuccess;

                // if email is changed, sync both email and username to it
                if (retrievedUser.Email != applicationUser.Email)
                {
                    // update the username
                    var previousUsername = retrievedUser.UserName;
                    retrievedUser.UserName = applicationUser.Email;
                    result = await UserManager.UpdateAsync(retrievedUser);

                    if (result.Succeeded)
                    {
                        result = await UserManager.SetEmailAsync(retrievedUser.Id, applicationUser.Email);

                        if (result.Succeeded)
                        {
                            manageMessageId = ManageMessageId.ChangeEmailSuccess;

                            var code = await UserManager.GenerateEmailConfirmationTokenAsync(retrievedUser.Id);

                            var callbackUrl = Url.Action(
                                "ConfirmEmail",
                                "Account",
                                new { userId = retrievedUser.Id, code = code, Request.Url.Scheme });

                            await UserManager.SendEmailAsync(
                                retrievedUser.Id,
                                "Confirm your account",
                                "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                        }
                        else
                        {
                            retrievedUser.UserName = previousUsername;
                            result = await UserManager.UpdateAsync(retrievedUser);

                            manageMessageId = ManageMessageId.Error;
                        }
                    }
                    else
                    {
                        retrievedUser.UserName = previousUsername;
                        result = await UserManager.UpdateAsync(retrievedUser);

                        manageMessageId = ManageMessageId.Error;
                    }
                }
                else
                {
                    manageMessageId = ManageMessageId.Error;
                }
            }
            return(RedirectToAction("Index", new { Message = manageMessageId }));
        }
Esempio n. 43
0
        public async Task <ActionResult> RemovePhoneNumber()
        {
            ManageMessageId message = await _manageUsersService.RemovePhoneNumber(User.Identity.GetUserId());

            return(RedirectToAction("Index", new { Message = message }));
        }
Esempio n. 44
0
        public async Task <ActionResult> ChangeEmail(ChangeEmailViewModel model)
        {
            var userId = User.Identity.GetUserId();

            string[] sArr   = { "0", "0" };
            var      claims = await UserManager.GetClaimsAsync(userId);

            var             existingClaim = claims.FirstOrDefault(c => c.Type == "FullName");
            ManageMessageId msg           = ManageMessageId.NoActions;
            string          FullName      = null;

            if (existingClaim != null)
            {
                FullName = existingClaim.Value;
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByIdAsync(userId);

            if (user != null)
            {
                if (model.Email != user.Email)
                {
                    var userCurr = await UserManager.FindByEmailAsync(model.Email);

                    if (userCurr != null)
                    {
                        ModelState.AddModelError("Email", "Пользователь с электронной почтой " + model.Email + " уже зарегистрирован!");
                        Data.Save_log.Log("Ошибка изменения имени пользователя/email. Пользователь с электронной почтой " + model.Email + " уже зарегистрирован!", "ManageLogin");
                        return(View(model));
                    }
                    Data.Save_log.Log("Изменение email с " + user.Email + " на " + model.Email, "ManageLogin");
                    user.Email          = model.Email;
                    user.EmailConfirmed = false;
                    var result = await UserManager.UpdateAsync(user);

                    if (result.Succeeded == false)
                    {
                        Data.Save_log.Log("Изменение email выполнено. Пользователь " + user.UserName, "ManageLogin");
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        Data.Save_log.Log("Для пользователя " + user.UserName + " изменен email " + model.Email + ". Отправлено подтверждение по почте.", "ManageLogin");
                        await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>");

                        return(RedirectToAction("Index", new { Message = ManageMessageId.EmailChanged }));
                    }
                    else
                    {
                        Data.Save_log.Log("Пользователь " + user.UserName + " " + result.Errors.ToString() + ".", "ManageLogin");
                        ModelState.AddModelError("UserName", "Пользователь " + user.UserName + " " + result.Errors.ToString() + ".");
                        AddErrors(result);
                        return(View(model));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", new { Message = msg }));
                }
            }
            return(RedirectToAction("Index"));
        }