public void IndexActionShouldReturnTheModelIfPostIsNotValid() { var feedback = new FeedbackReport { Name = "Ivaylo", Content = "Test", }; var user = new UserProfile { UserName = LoggedUserName, Email = "*****@*****.**", }; this.EmptyOjsData.Users.Add(user); this.EmptyOjsData.SaveChanges(); var controller = new FeedbackController(EmptyOjsData); // assign the fake context var context = new ControllerContext(this.MockHttpContextBasePost(), new RouteData(), controller); controller.ControllerContext = context; var result = controller.Index(feedback, true) as ViewResult; var model = result.Model as FeedbackReport; Assert.AreEqual(model.Name, feedback.Name); Assert.AreEqual(model.Content, feedback.Content); }
public void Copy(OjsDbContext context, TelerikContestSystemEntities oldDb) { context.Configuration.AutoDetectChangesEnabled = false; var users = oldDb.Users.OrderBy(x => x.Id).Select( x => new { x.aspnet_Users.UserName, x.aspnet_Users.aspnet_Membership.Email, Profile = x, HasAnyParticipationWithSubmissions = x.Participants.Any(y => y.Submissions.Any()), CreatedOn = x.aspnet_Users.aspnet_Membership.CreateDate, x.Id, }) .Where(x => x.HasAnyParticipationWithSubmissions); //// .Where(x => !x.UserName.StartsWith("*****@*****.**")) //// .Where(x => !x.Email.StartsWith("*****@*****.**")) //// .Where(x => x.Profile.LastName != "*****@*****.**") //// .Where(x => !x.UserName.Contains("\'") && !x.UserName.Contains("\\") && !x.UserName.Contains("/") && !x.UserName.Contains("%") && !x.UserName.Contains(")")); foreach (var oldUser in users) { var dateOfBirth = oldUser.Profile.DateOfBirth; if (dateOfBirth.HasValue && dateOfBirth.Value.Year < 1900) { dateOfBirth = null; } if (dateOfBirth.HasValue && dateOfBirth.Value.Year > 2006) { dateOfBirth = null; } var user = new UserProfile(oldUser.UserName.Trim(), oldUser.Email.Trim()) { UserSettings = new UserSettings { FirstName = oldUser.Profile.FirstName.Trim().MaxLength(30), LastName = oldUser.Profile.LastName.Trim().MaxLength(30), City = oldUser.Profile.City.MaxLength(30), DateOfBirth = dateOfBirth, EducationalInstitution = oldUser.Profile.EducationalInstitution.MaxLength(50), FacultyNumber = oldUser.Profile.FacultyNumber.MaxLength(30), Company = oldUser.Profile.Company.MaxLength(30), JobTitle = oldUser.Profile.JobTitle.MaxLength(30), }, IsGhostUser = true, OldId = oldUser.Id, PreserveCreatedOn = true, CreatedOn = oldUser.CreatedOn, }; context.Users.Add(user); } context.SaveChanges(); context.Configuration.AutoDetectChangesEnabled = true; }
public UserProfileViewModel(UserProfile profile) { this.Username = profile.UserName; this.FirstName = profile.UserSettings.FirstName; this.LastName = profile.UserSettings.LastName; this.City = profile.UserSettings.City; this.Age = profile.UserSettings.Age; this.Participations = new HashSet<UserParticipationViewModel>(); }
protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state) { // Work with data before BeginExecute to prevent "NotSupportedException: A second operation started on this context before a previous asynchronous operation completed." this.UserProfile = this.Data.Users.GetByUsername(requestContext.HttpContext.User.Identity.Name); // Calling BeginExecute before PrepareSystemMessages for the TempData to has values var result = base.BeginExecute(requestContext, callback, state); var systemMessages = this.PrepareSystemMessages(); this.ViewBag.SystemMessages = systemMessages; return result; }
public UserSettingsViewModel(UserProfile profile) { this.Username = profile.UserName; this.Email = profile.Email; this.FirstName = profile.UserSettings.FirstName; this.LastName = profile.UserSettings.LastName; this.DateOfBirth = profile.UserSettings.DateOfBirth; this.City = profile.UserSettings.City; this.EducationalInstitution = profile.UserSettings.EducationalInstitution; this.FacultyNumber = profile.UserSettings.FacultyNumber; this.Company = profile.UserSettings.Company; this.JobTitle = profile.UserSettings.JobTitle; this.Age = profile.UserSettings.Age; }
protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state) { // Work with data before BeginExecute to prevent "NotSupportedException: A second operation started on this context before a previous asynchronous operation completed." this.UserProfile = this.Data.Users.GetByUsername(requestContext.HttpContext.User.Identity.Name); this.ViewBag.MainCategories = this.Data.ContestCategories.All() .Where(x => x.IsVisible && !x.ParentId.HasValue) .OrderBy(x => x.OrderBy) .Select(CategoryMenuItemViewModel.FromCategory); // Calling BeginExecute before PrepareSystemMessages for the TempData to has values var result = base.BeginExecute(requestContext, callback, state); var systemMessages = this.PrepareSystemMessages(); this.ViewBag.SystemMessages = systemMessages; return result; }
public void GetSubmissionContentWhenSubmissionNotMadeByTheParticipantShouldThrowException() { var contest = this.CreateAndSaveContest("sample Name", this.ActiveContestNoPasswordOptions, this.ActiveContestNoPasswordOptions); var problem = new Problem(); contest.Problems.Add(problem); var submissionType = new SubmissionType(); contest.SubmissionTypes.Add(submissionType); var participant = new Participant(contest.Id, this.FakeUserProfile.Id, this.IsCompete); var anotherUser = new UserProfile { UserName = "******", Email = "*****@*****.**" }; this.EmptyOjsData.Users.Add(anotherUser); var anotherParticipant = new Participant(contest.Id, anotherUser.Id, this.IsCompete); contest.Participants.Add(participant); contest.Participants.Add(anotherParticipant); var submission = new Submission { ContentAsString = "test content" }; anotherParticipant.Submissions.Add(submission); this.EmptyOjsData.SaveChanges(); try { var result = this.CompeteController.GetSubmissionContent(submission.Id); Assert.Fail("Expected an exception when trying to download a submission that was not made by the participant that requested it."); } catch (HttpException ex) { Assert.AreEqual((int)HttpStatusCode.Forbidden, ex.GetHttpCode()); } }
public BaseController(IOjsData data, UserProfile profile) : this(data) { this.UserProfile = profile; }
public CompeteController(IOjsData data, UserProfile userProfile) : base(data, userProfile) { }
public async Task<ActionResult> Register(RegisterViewModel model, bool captchaValid) { if (this.Data.Users.All().Any(x => x.Email == model.Email)) { this.ModelState.AddModelError("Email", Resources.Account.AccountViewModels.Email_already_registered); } if (this.Data.Users.All().Any(x => x.UserName == model.UserName)) { this.ModelState.AddModelError("UserName", Resources.Account.AccountViewModels.User_already_registered); } if (!captchaValid) { this.ModelState.AddModelError("Captcha", Resources.Account.Views.General.Captcha_invalid); } if (this.ModelState.IsValid) { var user = new UserProfile { UserName = model.UserName, Email = model.Email }; var result = await this.UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await this.SignInAsync(user, isPersistent: false); return this.RedirectToAction(GlobalConstants.Index, "Home"); } this.AddErrors(result); } // If we got this far, something failed, redisplay form return this.View(model); }
private async Task SignInAsync(UserProfile user, bool isPersistent) { this.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await this.UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); this.AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, identity); }
private void SendForgottenPasswordToUser(UserProfile user) { var mailSender = MailSender.Instance; var forgottenPasswordEmailTitle = string.Format( Resources.Account.AccountEmails.Forgotten_password_title, user.UserName); var forgottenPasswordEmailBody = string.Format( Resources.Account.AccountEmails.Forgotten_password_body, user.UserName, this.Url.Action("ChangePassword", "Account", new { token = user.ForgottenPasswordToken }, this.Request.Url.Scheme)); mailSender.SendMail(user.Email, forgottenPasswordEmailTitle, forgottenPasswordEmailBody); }
public async Task<ActionResult> ExternalLoginConfirmation( ExternalLoginConfirmationViewModel model, string returnUrl) { if (this.User.Identity.IsAuthenticated) { return this.RedirectToAction("Manage"); } if (this.ModelState.IsValid) { // Get the information about the user from the external login provider var info = await this.AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return this.View("ExternalLoginFailure"); } if (this.Data.Users.All().Any(x => x.Email == model.Email)) { this.TempData[GlobalConstants.DangerMessage] = Resources.Account.Views.ExternalLoginConfirmation.Email_already_registered; return this.RedirectToAction("ForgottenPassword"); } if (this.Data.Users.All().Any(x => x.UserName == model.UserName)) { this.ModelState.AddModelError("Username", Resources.Account.Views.ExternalLoginConfirmation.User_already_registered); } if (!this.ModelState.IsValid) { return this.View(model); } var user = new UserProfile { UserName = model.UserName, Email = model.Email }; var result = await this.UserManager.CreateAsync(user); if (result.Succeeded) { result = await this.UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await this.SignInAsync(user, isPersistent: false); return this.RedirectToLocal(returnUrl); } } this.AddErrors(result); } this.ViewBag.ReturnUrl = returnUrl; return this.View(model); }