Пример #1
0
        public async Task <IActionResult> Register(MvcRegisterViewModel model, string returnUrl = null)
        {
            var reCaptchaValid = IsReCaptchValid();

            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid && reCaptchaValid)
            {
                ApplicationUser user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, CreateDate = DateTime.Now
                };

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

                if (result.Succeeded)
                {
                    ProfileViewModel profile = profileAppService.GenerateNewOne(ProfileType.Personal);
                    profile.UserId  = new Guid(user.Id);
                    profile.Handler = model.UserName;
                    profileAppService.Save(CurrentUserId, profile);

                    UploadFirstAvatar(profile.UserId, ProfileType.Personal);

                    await SetStaffRoles(user);

                    SetPreferences(user);

                    string logMessage = String.Format("User {0} created a new account with password.", model.UserName);

                    if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        await NotificationSender.SendTeamNotificationAsync(logMessage);
                    }

                    _logger.LogInformation(logMessage);

                    string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    string callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await NotificationSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User logged in with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Details(Guid id, Guid notificationclicked)
        {
            ProfileViewModel vm = profileAppService.GetByUserId(CurrentUserId, id, ProfileType.Personal);

            if (vm == null)
            {
                ProfileViewModel profile = profileAppService.GenerateNewOne(ProfileType.Personal);

                ApplicationUser user = await UserManager.FindByIdAsync(id.ToString());

                if (user != null)
                {
                    profile.UserId = id;
                    profileAppService.Save(CurrentUserId, profile);
                }
                else
                {
                    TempData["Message"] = SharedLocalizer["User not found!"].Value;
                    return(RedirectToAction("Index", "Home"));
                }

                vm = profile;
            }

            gamificationAppService.FillProfileGamificationDetails(CurrentUserId, ref vm);

            if (CurrentUserId != Guid.Empty)
            {
                ApplicationUser user = await UserManager.FindByIdAsync(CurrentUserId.ToString());

                bool userIsAdmin = await UserManager.IsInRoleAsync(user, Roles.Administrator.ToString());

                vm.Permissions.IsAdmin    = userIsAdmin;
                vm.Permissions.CanEdit    = vm.UserId == CurrentUserId;
                vm.Permissions.CanFollow  = vm.UserId != CurrentUserId;
                vm.Permissions.CanConnect = vm.UserId != CurrentUserId;

                if (notificationclicked != Guid.Empty)
                {
                    notificationAppService.MarkAsRead(notificationclicked);
                }
            }

            ViewData["ConnecionTypes"] = EnumExtensions.ToJson(UserConnectionType.Mentor);

            return(View(vm));
        }
Пример #3
0
        public IActionResult Index()
        {
            ProfileViewModel model = profileAppService.GenerateNewOne(ProfileType.Personal);

            return(View(model));
        }