public void OnAuthentication(AuthenticationContext filterContext) { var cookies = filterContext.HttpContext.Request.Cookies; IPrincipal principal = null; var cookieContext = cookies[Security.Constants.CookieName]; if (cookieContext != null) { var authService = this.Container.Resolve <IAuthService>(); var user = authService.GetUserFromCookie(cookieContext); if (user != null) { IIdentity identity = new IndentityUser(user.Login); principal = new IdentityPrincipal(identity); } } if (principal == null) { IIdentity user = new AnonymousUser(); principal = new IdentityPrincipal(user); } filterContext.Principal = principal; filterContext.HttpContext.User = principal; Thread.CurrentPrincipal = principal; }
AnonymousContact IAnonymousUsersCommand.CreateContact(AnonymousUser user, ContactDetails contactDetails) { // Look for an existing contact. var contact = _repository.GetContact(user, contactDetails); if (contact != null) { return(contact); } // Create a new contact. user.Prepare(); user.Validate(); contact = new AnonymousContact { EmailAddress = contactDetails.EmailAddress, FirstName = contactDetails.FirstName, LastName = contactDetails.LastName }; contact.Prepare(); contact.Validate(); _repository.CreateContact(user, contact); return(contact); }
public ActionResult Index(UserViewModel user, string submit) { var userObj = new AnonymousUser { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Address = user.Address, PhoneNumber = user.PhoneNumber }; if (ModelState.IsValid) { var cookie = Request.Cookies["customer_id"]; userObj.ID = Int32.Parse(cookie.Value); db.Entry(userObj).State = EntityState.Modified; db.SaveChanges(); TempData["update-msg"] = "<script>alert('Cập nhật thông tin thành công');</script>"; } if (submit.Equals("Cập nhật và mua hàng")) { Checkout(); } return(View(user)); }
/// <summary> /// Updates information about a user in the data source. /// </summary> /// <param name="user">A <see cref="T:System.Web.Security.MembershipUser" /> object that represents the user to update and the updated information for the user.</param> public override void UpdateUser(MembershipUser user) { if (AnonymousUser.UserIsNotAnonymous(user.UserName)) { base.UpdateUser(user); } }
public async Task <IActionResult> PutAnonymousUser([FromRoute] Guid id, [FromBody] AnonymousUser anonymousUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != anonymousUser.Id) { return(BadRequest()); } _context.Entry(anonymousUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnonymousUserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,AppVersion,UserAgent,CreationDate")] AnonymousUser anonymousUser) { if (id != anonymousUser.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(anonymousUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnonymousUserExists(anonymousUser.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(anonymousUser)); }
public async Task <IHttpActionResult> CreateUser(AnonymousUser aUser) { if (ModelState.IsValid) { var user = new Users() { Email = aUser.Email, FirstName = aUser.FirstName, LastName = aUser.LastName, PasswordHash = aUser.Password, Organization = aUser.Organization, UserName = aUser.Email }; IdentityResult addUserResult = await this.userManager.CreateAsync(user, aUser.Password); if (addUserResult.Succeeded) { this.userManager.AddToRole(user.Id, "User"); return(Created(new Uri(Url.Link("GetRegdUser", new { id = user.Id })), new{ Message = "User has been registered successfully" })); } else { return(GetErrorResult(addUserResult)); } } else { return(BadRequest(ModelState)); } }
public HttpResponseMessage Get(Guid personGuid) { if (personGuid == null) { return(Request.CreateResponse(HttpStatusCode.NoContent, new HttpError(ErrorInfo.UserNotFound))); } // var person = ProfileDbContext.People.Where(p => p.PersonGuid.Equals(personGuid)).FirstOrDefault(); var personDetail = ProfileDbContext.PersonDetails.Where(p => p.FinanceServiceGuid.Equals(personGuid)).FirstOrDefault(); if (personDetail == null) { return(Request.CreateResponse(HttpStatusCode.NoContent, new HttpError(ErrorInfo.UserNotFound))); } if (personDetail.DomainId != DomainId) { return(Request.CreateResponse(HttpStatusCode.NoContent, new HttpError(ErrorInfo.UserNotFound))); } //var personDetail = personDetails.Where(p => p.DomainId.Equals(DomainId)).FirstOrDefault(); var anonymousUser = new AnonymousUser() { DomainId = DomainId, // Changes done for Edit_Email. Email = /*person.Email*/ personDetail.Email, FirstName = personDetail.FirstName, LastName = personDetail.LastName, PersonGuid = personGuid, Gender = personDetail.Gender, DOB = personDetail.DateOfBirth.GetDecryptNullableDateTime(), HomeAirport = personDetail.HomeAirPort }; return(Request.CreateResponse(HttpStatusCode.OK, anonymousUser)); }
private JobAd CreateJobAd(IEmployer employer, AnonymousUser anonymousUser, JobAdModel jobAdModel, HttpPostedFileBase logo, Guid?logoId) { CreateLogo(jobAdModel, logo, logoId); // Prepare it first. jobAdModel.Prepare(); // Update a new instance. var jobAd = new JobAd(); UpdateJobAd(jobAd, jobAdModel); // Create the job ad. if (employer != null) { _employerJobAdsCommand.CreateJobAd(employer, jobAd); } else { _anonymousJobAdsCommand.CreateJobAd(anonymousUser, jobAd); } return(jobAd); }
/// <summary> /// If "no customer id" access the web => gen a new customer /// </summary> private AnonymousUser CheckCustomerId() { string customerId = ""; AnonymousUser customer = null; var cookie = Request.Cookies["customer_id"]; if (cookie != null) { customerId = cookie.Value; int cusId = int.Parse(customerId); customer = db.AnonymousUsers.Find(cusId); if (customer == null) { cookie = null; } } if (cookie == null) { customer = new AnonymousUser(); db.AnonymousUsers.Add(customer); db.SaveChanges(); customerId = customer.ID.ToString(); } Response.Cookies["customer_id"].Value = customerId; Response.Cookies["customer_id"].Expires = DateTime.Now.AddDays(30); return(customer); }
public void TestCreateOtherContact() { var user = new AnonymousUser(); var contactDetails1 = CreateContactDetails(0); var contactDetails2 = CreateContactDetails(1); var contact1 = _anonymousUsersCommand.CreateContact(user, contactDetails1); AssertContact(contact1.Id, contactDetails1, contact1); AssertContact(contact1.Id, contactDetails1, _anonymousUsersQuery.GetContact(contact1.Id)); var contact2 = _anonymousUsersCommand.CreateContact(user, contactDetails2); AssertContact(contact2.Id, contactDetails2, contact2); AssertContact(contact2.Id, contactDetails2, _anonymousUsersQuery.GetContact(contact2.Id)); Assert.AreNotEqual(contact1.Id, contact2.Id); var contact = _anonymousUsersCommand.CreateContact(user, contactDetails1); AssertContact(contact1.Id, contactDetails1, contact); AssertContact(contact1.Id, contactDetails1, _anonymousUsersQuery.GetContact(contact1.Id)); contact = _anonymousUsersCommand.CreateContact(user, contactDetails2); AssertContact(contact2.Id, contactDetails2, contact); AssertContact(contact2.Id, contactDetails2, _anonymousUsersQuery.GetContact(contact2.Id)); }
/// <summary> /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user. /// </summary> /// <param name="username">The name of the user to get information for.</param> /// <param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser" /> object populated with the specified user's information from the data source. /// </returns> public override MembershipUser GetUser(string username, bool userIsOnline) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.GetUser(username, userIsOnline)); } return(null); }
/// <summary> /// Removes a user from the membership data source. /// </summary> /// <param name="username">The name of the user to delete.</param> /// <param name="deleteAllRelatedData">true to delete data related to the user from the database; false to leave data related to the user in the database.</param> /// <returns> /// true if the user was successfully deleted; otherwise, false. /// </returns> public override bool DeleteUser(string username, bool deleteAllRelatedData) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.DeleteUser(username, deleteAllRelatedData)); } return(false); }
/// <summary> /// Processes a request to update the password question and answer for a contact. /// </summary> /// <param name="username">The contact to change the password question and answer for.</param> /// <param name="password">The password for the specified contact.</param> /// <param name="newPasswordQuestion">The new password question for the specified contact.</param> /// <param name="newPasswordAnswer">The new password answer for the specified contact.</param> /// <returns> /// true if the password question and answer are updated successfully; otherwise, false. /// </returns> public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.ChangePasswordQuestionAndAnswer(username, password, newPasswordQuestion, newPasswordAnswer)); } return(false); }
/// <summary> /// Clears a lock so that the membership user can be validated. The locked users isn't supported by the provider. /// </summary> /// <param name="userName">The membership user whose lock status you want to clear.</param> /// <returns> /// true if the membership user was successfully unlocked; otherwise, false. /// </returns> public override bool UnlockUser(string userName) { if (AnonymousUser.UserIsNotAnonymous(userName)) { return(base.UnlockUser(userName)); } return(false); }
/// <summary> /// Gets a list of the roles that a specified user is in for the configured applicationName. /// </summary> /// <param name="userName">The user to return a list of roles for.</param> /// <returns> /// A string array containing the names of all the roles that the specified user is in for the configured applicationName. /// </returns> public override string[] GetRolesForUser(string userName) { if (AnonymousUser.UserIsNotAnonymous(userName)) { return(base.GetRolesForUser(userName)); } return(EnumerableConstants.EmptyStrings); }
/// <summary> /// Verifies that the specified contact name and password exist in the CRM system. /// </summary> /// <param name="username">The name of the contact to validate.</param> /// <param name="password">The password for the specified contact.</param> /// <returns> /// true if the specified contact name and password are valid; otherwise, false. /// </returns> public override bool ValidateUser(string username, string password) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.ValidateUser(username, password)); } return(false); }
/// <summary> /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName. /// </summary> /// <param name="username">The user name to search for.</param> /// <param name="roleName">The role to search in.</param> /// <returns> /// true if the specified user is in the specified role for the configured applicationName; otherwise, false. /// </returns> public override bool IsUserInRole(string username, string roleName) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.IsUserInRole(username, roleName)); } return(false); }
public ActionResult DeleteConfirmed(int id) { AnonymousUser anonymousUser = db.AnonymousUser.Find(id); db.AnonymousUser.Remove(anonymousUser); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Processes a request to update the password for a contact. /// </summary> /// <param name="username">The contact to update the password for.</param> /// <param name="oldPassword">The current password for the specified contact.</param> /// <param name="newPassword">The new password for the specified contact.</param> /// <returns> /// true if the password was updated successfully; otherwise, false. /// </returns> public override bool ChangePassword(string username, string oldPassword, string newPassword) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.ChangePassword(username, oldPassword, newPassword)); } return(false); }
/// <summary> /// Creates a new anonymous user by id. /// </summary> /// <param name="id">The id.</param> /// <returns>The anonymous user.</returns> public Task <IAnonymousUser> CreateAsync(string id = null) { var user = new AnonymousUser() { Id = id ?? Guid.NewGuid().ToString() }; return(Task.FromResult <IAnonymousUser>(user)); }
void IAnonymousJobAdsCommand.UpdateJobAd(AnonymousUser user, JobAd jobAd) { if (!CanAccess(user, jobAd)) { throw new JobAdPermissionsException(user, jobAd.Id); } _jobAdsCommand.UpdateJobAd(jobAd); }
/// <summary> /// Sets the values of the specified group of property settings. /// </summary> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext" /> describing the current application usage.</param> /// <param name="collection">A <see cref="T:System.Configuration.SettingsPropertyValueCollection" /> representing the group of property settings to set.</param> public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) { var userName = (string)context["UserName"]; if (AnonymousUser.UserIsNotAnonymous(userName)) { base.SetPropertyValues(context, collection); } }
/// <summary> /// Adds a new contact to the CRM system. /// </summary> /// <param name="username">The name for the new contact.</param> /// <param name="password">The password for the new contact.</param> /// <param name="email">The e-mail address for the new contact.</param> /// <param name="passwordQuestion">The password question for the new contact.</param> /// <param name="passwordAnswer">The password answer for the new contact.</param> /// <param name="isApproved">Whether or not the new contact is approved to be validated.</param> /// <param name="providerUserKey">The unique identifier for the contact.</param> /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus" /> enumeration value indicating whether the contact was created successfully.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser" /> object populated with the information for the newly created contact. /// </returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (AnonymousUser.UserIsNotAnonymous(username)) { return(base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status)); } status = MembershipCreateStatus.UserRejected; return(null); }
public User Authenticate(AnonymousUser user) { var registeredUser = _context.Users.Where(u => u.Username.Equals(user.Username) && u.Password.Equals(user.Password)).FirstOrDefault(); if (registeredUser == null) { return(null); } return(new Employee(registeredUser.Username)); }
/// <summary> /// Returns the collection of settings property values for the specified application instance and settings property group. /// </summary> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext" /> describing the current application use.</param> /// <param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection" /> containing the settings property group whose values are to be retrieved.</param> /// <returns> /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection" /> containing the values for the specified settings property group. /// </returns> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var userName = (string)context["UserName"]; if (AnonymousUser.UserIsNotAnonymous(userName)) { return(base.GetPropertyValues(context, collection)); } return(new SettingsPropertyValueCollection()); }
public ActionResult Edit([Bind(Include = "ID")] AnonymousUser anonymousUser) { if (ModelState.IsValid) { db.Entry(anonymousUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(anonymousUser)); }
public ActionResult Create([Bind(Include = "ID")] AnonymousUser anonymousUser) { if (ModelState.IsValid) { db.AnonymousUser.Add(anonymousUser); db.SaveChanges(); return(RedirectToAction("Details")); } return(View(anonymousUser)); }
private async Task SetCredentialsAsync(AnonymousUser user) { var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.Role, user.Role.ToString()) }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var userPrincipal = new ClaimsPrincipal(claimsIdentity); await _authenticationService.SignInAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new AuthenticationProperties { IsPersistent = true }); }
private void SetCredentialsFromTo(AnonymousUser anonymousUser, RegisteredUser user) { var loggedInUser = new PrincipalAdapter <int, MvcMusicStore.Models.Enums.Roles>(user.Username, user.Id, new GenericIdentity(user.Username), user.Role); this.HttpContext.User = loggedInUser; var cookie = new HttpCookie("user"); cookie.Values.Add("isAnonymous", false.ToString()); cookie.Values.Add("userId", user.Id.ToString()); this.Response.Cookies.Set(cookie); this.TypedSession = loggedInUser; }