Esempio n. 1
0
        private void EnvParameterChanged()
        {
            var validFolder = !CondaEnvExists(RegistryService, EnvName);

            // For now, we enable but prompt when they click accept
            //if (IsEnvFile) {
            //    IsAcceptEnabled = validFolder && File.Exists(SelectedEnvFilePath);
            //} else {
            //    IsAcceptEnabled = validFolder;
            //}

            if (string.IsNullOrEmpty(EnvName.Trim()))
            {
                SetError(nameof(EnvName), Strings.AddCondaEnvironmentNameEmpty);
            }
            else if (!validFolder)
            {
                SetError(nameof(EnvName), Strings.AddCondaEnvironmentNameInvalid.FormatUI(EnvName ?? string.Empty));
            }
            else
            {
                ClearErrors(nameof(EnvName));
            }

            if (IsEnvFile && !File.Exists(SelectedEnvFilePath))
            {
                SetError(nameof(SelectedEnvFilePath), Strings.AddCondaEnvironmentFileInvalid.FormatUI(SelectedEnvFilePath ?? string.Empty));
            }
            else
            {
                ClearErrors(nameof(SelectedEnvFilePath));
            }

            TriggerDelayedPreview();
        }
Esempio n. 2
0
        public async Task <IActionResult> Save(UserContentViewModel vm)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;

                ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal);

                SetAuthorDetails(vm);

                OperationResultVo <Guid> saveResult = userContentAppService.Save(CurrentUserId, vm);

                if (!saveResult.Success)
                {
                    return(Json(saveResult));
                }
                else
                {
                    NotifyFollowers(profile, vm.GameId, vm.Id);

                    string url = Url.Action("Index", "Home", new { area = string.Empty, id = vm.Id, pointsEarned = saveResult.PointsEarned });

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        await NotificationSender.SendTeamNotificationAsync("New complex post!");
                    }

                    return(Json(new OperationResultRedirectVo(url)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> SimplePost(string text, string images, IEnumerable <PollOptionViewModel> pollOptions, SupportedLanguage?language, Guid?gameId)
        {
            UserContentViewModel vm = new UserContentViewModel
            {
                Language = language ?? SupportedLanguage.English,
                Content  = text,
                Poll     = new PollViewModel
                {
                    PollOptions = pollOptions.ToList()
                },
                GameId = gameId
            };

            ProfileViewModel profile = await ProfileAppService.GetByUserId(CurrentUserId, ProfileType.Personal);

            SetAuthorDetails(vm);

            SetContentImages(vm, images);

            OperationResultVo <Guid> result = userContentAppService.Save(CurrentUserId, vm);

            NotifyFollowers(profile, vm.GameId, vm.Id);

            if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
            {
                await NotificationSender.SendTeamNotificationAsync("New simple post!");
            }

            return(Json(result));
        }
Esempio n. 4
0
        public JsonResult SaveGiveaway(GiveawayViewModel vm)
        {
            bool isNew = vm.Id == Guid.Empty;

            try
            {
                vm.UserId = CurrentUserId;

                OperationResultVo <Guid> saveResult = giveawayAppService.SaveGiveaway(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    string url = Url.Action("edit", "giveaway", new { area = "tools", id = vm.Id, pointsEarned = saveResult.PointsEarned });

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        NotificationSender.SendTeamNotificationAsync("New Giveaway created!");
                    }

                    return(Json(new OperationResultRedirectVo <Guid>(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 5
0
        public IActionResult Save(GameViewModel vm, IFormFile thumbnail)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;

                SetAuthorDetails(vm);
                ClearImagesUrl(vm);

                OperationResultVo <Guid> saveResult = gameAppService.Save(CurrentUserId, vm);

                if (!saveResult.Success)
                {
                    return(Json(saveResult));
                }
                else
                {
                    string url = Url.Action("Details", "Game", new { area = string.Empty, id = vm.Id.ToString(), pointsEarned = saveResult.PointsEarned });

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        NotificationSender.SendTeamNotificationAsync($"New game Created: {vm.Title}");
                    }

                    return(Json(new OperationResultRedirectVo(url)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 6
0
        private async Task <IActionResult> ManageSuccessfullLogin(LoginViewModel model, string returnUrl)
        {
            ApplicationUser user = await _userManager.FindByNameAsync(model.UserName);

            if (user != null && !string.IsNullOrWhiteSpace(user.UserName))
            {
                SetEmailConfirmed(user);

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

                await SetStaffRoles(user);

                SetPreferences(user);

                await SetCache(user);
            }

            string logMessage = String.Format("User {0} logged in.", model.UserName);

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

            _logger.LogInformation(logMessage);

            return(RedirectToLocal(returnUrl));
        }
Esempio n. 7
0
        public JsonResult Save(GamificationLevelViewModel vm)
        {
            bool isNew = vm.Id == Guid.Empty;

            try
            {
                vm.UserId = CurrentUserId;

                OperationResultVo <Guid> saveResult = gamificationLevelAppService.Save(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    string url = Url.Action("index", "gamificationlevel", new { area = "staff" });

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        NotificationSender.SendTeamNotificationAsync("New Gamification Level created!");
                    }

                    return(Json(new OperationResultRedirectVo <Guid>(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 8
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));
        }
Esempio n. 9
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));
        }
Esempio n. 10
0
        public async Task <IActionResult> Enter(GiveawayEnterViewModel enter)
        {
            try
            {
                string urlReferalBase = Url.Action("details", "giveaway", new { area = "tools", id = enter.GiveawayId });

                OperationResultVo result = giveawayAppService.EnterGiveaway(CurrentUserId, enter, urlReferalBase);

                if (result.Success)
                {
                    OperationResultVo <string> castRestult = result as OperationResultVo <string>;

                    SetSessionValue(SessionValues.Email, enter.Email);

                    OperationResultVo resultGiveawayInfo = giveawayAppService.GetForEdit(CurrentUserId, enter.GiveawayId);

                    if (resultGiveawayInfo.Success)
                    {
                        OperationResultVo <GiveawayViewModel> castRestultGiveawayInfo = resultGiveawayInfo as OperationResultVo <GiveawayViewModel>;

                        if (!string.IsNullOrWhiteSpace(castRestult.Value))
                        {
                            string emailConfirmationUrl = Url.GiveawayEmailConfirmationLink(Request.Scheme, enter.GiveawayId.ToString(), castRestult.Value);

                            await NotificationSender.SendGiveawayEmailConfirmationAsync(enter.Email, emailConfirmationUrl, castRestultGiveawayInfo.Value.Name);

                            if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                            {
                                await NotificationSender.SendTeamNotificationAsync(String.Format("{0} joined the giveaway {1}", enter.Email, castRestultGiveawayInfo.Value.Name));
                            }
                        }
                    }

                    string url = Url.Action("youarein", "giveaway", new { area = "tools", id = enter.GiveawayId });

                    return(Json(new OperationResultRedirectVo(result, url)));
                }

                return(Json(result));
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 11
0
        public async Task <IActionResult> SaveCourse(CourseViewModel vm)
        {
            bool isNew = vm.Id == Guid.Empty;

            try
            {
                vm.UserId = CurrentUserId;

                OperationResultVo <Guid> saveResult = await studyAppService.SaveCourse(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    //GenerateFeedPost(vm);

                    string url = Url.Action("details", "course", new { area = "learn", id = saveResult.Value });

                    if (isNew)
                    {
                        url = Url.Action("edit", "course", new { area = "learn", id = saveResult.Value, pointsEarned = saveResult.PointsEarned });

                        if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                        {
                            await NotificationSender.SendTeamNotificationAsync("New Course created!");
                        }
                    }

                    return(Json(new OperationResultRedirectVo <Guid>(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 12
0
        public IActionResult Save(JobPositionViewModel vm)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;

                vm.UserId = CurrentUserId;

                if (!string.IsNullOrWhiteSpace(vm.ClosingDateText))
                {
                    vm.ClosingDate = DateTime.Parse(vm.ClosingDateText);
                }

                OperationResultVo <Guid> saveResult = jobPositionAppService.Save(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    GenerateFeedPost(vm);

                    string url = Url.Action("Details", "JobPosition", new { area = "Work", id = vm.Id, pointsEarned = saveResult.PointsEarned });

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        NotificationSender.SendTeamNotificationAsync("New Job Position posted!");
                    }

                    return(Json(new OperationResultRedirectVo(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 13
0
        public IActionResult Save(LocalizationViewModel vm)
        {
            bool isNew = vm.Id == Guid.Empty;

            try
            {
                vm.UserId = CurrentUserId;

                OperationResultVo <Guid> saveResult = translationAppService.Save(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    //GenerateFeedPost(vm);

                    string url = Url.Action("details", "localization", new { area = "tools", id = vm.Id });

                    if (isNew)
                    {
                        url = Url.Action("edit", "localization", new { area = "tools", id = vm.Id, pointsEarned = saveResult.PointsEarned });

                        if (EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                        {
                            NotificationSender.SendTeamNotificationAsync("New Localization Project created!");
                        }
                    }

                    return(Json(new OperationResultRedirectVo <Guid>(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 14
0
        public IActionResult Save(TeamViewModel vm)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;
                vm.UserId = CurrentUserId;

                IEnumerable <Guid> oldMembers = vm.Members.Where(x => x.Id != Guid.Empty).Select(x => x.Id);

                OperationResultVo <Guid> saveResult = teamAppService.Save(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    string url = Url.Action("Index", "Team", new { area = string.Empty, id = vm.Id.ToString(), pointsEarned = saveResult.PointsEarned });

                    Notify(vm, oldMembers);

                    bool recruiting = !vm.RecruitingBefore && vm.Recruiting;
                    GenerateTeamPost(vm, isNew, recruiting);

                    if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                    {
                        NotificationSender.SendTeamNotificationAsync($"New team Created: {vm.Name}");
                    }

                    return(Json(new OperationResultRedirectVo(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 15
0
        public IActionResult SaveSession(BrainstormSessionViewModel vm)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;

                vm.UserId = CurrentUserId;

                brainstormAppService.SaveSession(vm);

                string url = Url.Action("Index", "Brainstorm", new { area = string.Empty, id = vm.Id.ToString() });

                if (isNew && EnvName.Equals(ConstantHelper.ProductionEnvironmentName))
                {
                    NotificationSender.SendTeamNotificationAsync($"New brainstorm session created: {vm.Title}");
                }

                return(Json(new OperationResultRedirectVo(url)));
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }
Esempio n. 16
0
        public async Task <IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
        {
            if (remoteError != null)
            {
                ErrorMessage = $"Error from external provider: {remoteError}";
                return(RedirectToAction(nameof(Login)));
            }
            ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                return(RedirectToAction(nameof(Login)));
            }

            // Sign in the user with this external login provider if the user already has a login.
            Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent : false, bypassTwoFactor : true);

            if (result.Succeeded)
            {
                string          email        = info.Principal.FindFirstValue(ClaimTypes.Email);
                ApplicationUser existingUser = await _userManager.FindByEmailAsync(email);

                if (existingUser != null)
                {
                    string logMessage = String.Format("User {0} logged in with {1} provider.", existingUser.UserName, info.LoginProvider);

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

                    _logger.LogInformation(logMessage);

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

                    await SetStaffRoles(existingUser);

                    SetPreferences(existingUser);
                }

                return(RedirectToLocal(returnUrl));
            }

            if (result.IsLockedOut)
            {
                return(RedirectToAction(nameof(Lockout)));
            }
            else
            {
                // If the user does not have an account, then ask the user to create an account.
                ViewData["ReturnUrl"]     = returnUrl;
                ViewData["LoginProvider"] = info.LoginProvider;
                ViewData["ButtonText"]    = SharedLocalizer["Register"];
                string text = "You've successfully authenticated with your external account. Please choose a username to use and click the Register button to finish logging in.";

                string email = info.Principal.FindFirstValue(ClaimTypes.Email);

                MvcExternalLoginViewModel model = new MvcExternalLoginViewModel {
                    Email = email
                };

                ApplicationUser existingUser = await _userManager.FindByEmailAsync(email);

                if (existingUser != null)
                {
                    model.UserExists = true;
                    model.Username   = existingUser.UserName;

                    text = "Oh! It looks like you already have a user registered here with us. Check your info below and confirm to link your account to your external account.";

                    ViewData["ButtonText"] = SharedLocalizer["Link Acounts"];
                }
                else
                {
                    model.ProfileName = SelectName(info);
                }

                ViewData["RegisterText"] = SharedLocalizer[text];

                return(View("ExternalLogin", model));
            }
        }