public async Task <User> Register(string lastName, string firstName, string birthYear, string email, string password) { // Check parameters //Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(lastName)); //Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(firstName)); //Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(password)); //Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(email)); //Contract.Requires<ArgumentOutOfRangeException>(birthYear < DateTime.Now.Year - 1, "BirthYear should be less than current year"); // Hash password string passwordHash = BCrypt.Net.BCrypt.HashPassword(password); // Save to store string userId = await _userStore.Create(new User(null, lastName, firstName, birthYear, passwordHash, email)); User user = new User(userId, lastName, firstName, birthYear, passwordHash, email); DateTime tokenValidityDate = DateTime.UtcNow.AddMinutes(_defaultTokenValidityPeriod); string token = GenerateUserToken(email, tokenValidityDate, userId); user.AuthToken = token; user.AuthTokenExpiration = tokenValidityDate; // Send email var emailValidationToken = GenerateUserToken(email, DateTime.UtcNow.AddHours(2), userId, true); string originalEmailHtml = await File.ReadAllTextAsync(Path.Combine(BaseFunctionDirectory, "../Assets/mail-validateaccount.html")); originalEmailHtml = originalEmailHtml.Replace("%%YES_LINK%%", $"{_functionBaseUrl}/validate/{emailValidationToken}"); await SendEmail(email, originalEmailHtml, string.Empty, "Validation de ton compte Plastic Origins"); //Contract.Ensures(user != null); return(user); }
public async Task <IActionResult> Create(string userName) { var user = _userStore.Create(userName); HttpContext.Session.SetString("CurrentUserId", user.Id.ToString()); await _chatHub.Clients.All.ReceiveNewUser(user); return(Json(user)); }
public async Task <IActionResult> Register(RegisterModel model) { if (model != null) { ApplicationUser user = await _users.Create(model.Username, model.Password); } return(Ok()); }
public async Task <IActionResult> RegisterUser([FromBody] UserCreateDataRepresentation data) { return((await _userStore.Create( TrustDefaults.KnownRootIdentifier, TrustDefaults.KnownHomeResourceId, data.FromRepresentation(), Permission.FullControl | Permission.Owner, CallerCollectionRights.User )) .MakeUserUri(Url) .MakeCreated()); }
public async ValueTask <string> Create(RegisterUser request) { var id = Guid.NewGuid().ToString(); await _userStore.Create(new UserRecord { Id = id, Email = request.Email, PasswordHash = _crypto.Hash(request.Password, salt: request.Email) }); return(id); }
public CreateUserResult Create(CreateUserParameters parameters) { var validationErrors = _createUserValidator.Validate(parameters).ToList(); if (validationErrors.Any()) { return(CreateUserResult.CreateFailureResult(validationErrors)); } var hashedPassword = _passwordHasher.Hash(parameters.Password); _userStore.Create(parameters.EmailAddress, hashedPassword); return(CreateUserResult.CreateSuccessResult()); }
public async Task <User> AddOrUpdate(ChangedUser model) { var entity = model.Id.NotEmpty() ? await _store.Retrieve(model.Id) : null ; if (entity is Data.User) { await _store.Update( Mapper.Map(model, entity) ); } else { entity = await _store.Create( Mapper.Map <Data.User>(model) ); } _cache.Remove(entity.Id); return(Mapper.Map <User>(entity)); }
public async Task <IActionResult> RegisterUser([FromBody] UserCreateDataRepresentation data, string id) { (await _tenantStore.Get(id)) .ThrowObjectNotFoundExceptionIfNull("Invalid tenant"); var user = await _userStore.GetByExternalId(data.ExternalId); // Create the user if it doesn't already exist if (user.IsNull() || user.Id.IsNullOrWhitespace()) { // make the user var userId = await _userStore.Create( User.GetId(), id, data.FromRepresentation(), Permission.FullControl, CallerCollectionRights.User); // and stick it on the tenant await _tenantStore.IncludeUser(id, userId, Permission.Get, CallerCollectionRights.Tenant); Log.DebugFormat("New user {0} registered on tenant {1}", userId, id); // now, we have the identity user, link this into the new user return(userId .MakeUserUri(Url) .MakeCreated()); } // 409 if already on the tenant (await _tenantStore.IsRegisteredOnTenant(id, user.Id)) .ThrowInvalidOperationExceptionIf(exists => exists, "User already exists on tenant"); // 202 if now included await _tenantStore.IncludeUser(id, user.Id, Permission.Get, CallerCollectionRights.Tenant); Log.DebugFormat("Registered existing user {0} on tenant {1}", user.Id, id); return(user.Id .MakeUserUri(Url) .MakeAccepted()); }