Exemple #1
0
        private async Task <IActionResult> HandleSucessfullExternalLogin(string returnUrl, ExternalLoginInfo externalLoginInfo, ApplicationUser user, ApplicationUser existingUser)
        {
            if (existingUser == null)
            {
                await SetInitialRoles(user);
            }
            else
            {
                SetEmailConfirmed(existingUser);
                await SetStaffRoles(user);
            }

            SetPreferences(user);

            Guid             userGuid = new Guid(user.Id);
            ProfileViewModel profile  = await profileAppService.GetByUserId(userGuid, ProfileType.Personal);

            if (profile == null)
            {
                profile        = profileAppService.GenerateNewOne(ProfileType.Personal);
                profile.UserId = userGuid;

                profile.Handler = user.UserName;

                profile.Name = SelectName(externalLoginInfo);
            }

            await SetExternalProfilePicture(externalLoginInfo, user, profile);

            if (string.IsNullOrWhiteSpace(profile.ProfileImageUrl) || profile.ProfileImageUrl == Constants.DefaultAvatar)
            {
                UploadFirstAvatar(profile.UserId, ProfileType.Personal);
            }

            profileAppService.Save(CurrentUserId, profile);

            await SetProfileOnSession(new Guid(user.Id), user.UserName);

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

            string logMessage = String.Format("User {0} linked a {1} account.", user.UserName, externalLoginInfo.LoginProvider);

            if (existingUser == null)
            {
                logMessage = String.Format("User {0} registered with a {1} account.", user.UserName, externalLoginInfo.LoginProvider);
            }

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

            _logger.LogInformation(logMessage);

            return(RedirectToLocal(returnUrl));
        }
Exemple #2
0
        public async Task <OperationResultVo> Handle(DeleteUserFromPlatformRequest request, CancellationToken cancellationToken)
        {
            bool canDelete = true;

            var comments = await userContentAppService.GetCommentsByUserId(request.CurrentUserId, request.UserId);

            if (comments.Success)
            {
                var castResult = comments as OperationResultListVo <CommentViewModel>;

                canDelete = !castResult.Value.Any();
            }

            if (canDelete)
            {
                var profile = await profileAppService.GetByUserId(request.UserId, ProfileType.Personal, false);

                if (profile == null)
                {
                    return(new OperationResultVo(false, "Can't delete user"));
                }

                var result = profileAppService.Remove(request.CurrentUserId, profile.Id);

                return(result);
            }
            else
            {
                return(new OperationResultVo(false, "Can't delete user"));
            }
        }
Exemple #3
0
        public async Task <IActionResult> Edit(Guid userId)
        {
            ProfileViewModel vm = await profileAppService.GetByUserId(userId, ProfileType.Personal, true);

            OperationResultVo countriesResult = profileAppService.GetCountries(CurrentUserId);

            if (countriesResult.Success)
            {
                OperationResultListVo <SelectListItemVo> castResultCountries = countriesResult as OperationResultListVo <SelectListItemVo>;

                IEnumerable <SelectListItemVo> countries = castResultCountries.Value;

                List <SelectListItem> countriesDropDown = countries.ToSelectList();
                if (!string.IsNullOrWhiteSpace(vm.Country))
                {
                    countriesDropDown.ForEach(x => x.Selected = x.Value.Equals(vm.Country));
                }
                ViewBag.Countries = countriesDropDown;
            }
            else
            {
                ViewBag.Countries = new List <SelectListItem>();
            }

            return(View(vm));
        }
        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));
        }