public async Task <IActionResult> Post([FromBody] AppUserRegistration model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _service.Create(model); return(new OkObjectResult(user)); }
public async Task <ActionResult <ApiResponse <int> > > RegisterMobile(AppUserRegistration registration) { try { Random rand = new Random(); ConfirmationRequest request = new ConfirmationRequest { confirmationID = 0, confirmType = 4, resetTime = DateTime.Now, code = rand.Next(10000, 99999).ToString() }; await _context.ConfirmationRequests.AddAsync(request); await _context.SaveChangesAsync(); var user = new AppUser { createdDate = DateTime.Now, mobile = registration.mobile, isActive = 1, IsDeleted = 0, verified = 0, OTP = request.code, OTPExpireTime = DateTime.Now, }; await _context.AppUsers.AddAsync(user); await _context.SaveChangesAsync(); if (registration.mobile.Contains("+91")) { //Send SMS for indian customers var Message = $"{request.code} one time password to proceed on Truck account activation.It is valid till 5 mins.Do not share your OTP with anyone."; //await _repos.SendSMS(registration.mobile, Message); return(new ApiResponse <int> { code = 1, message = Message }); } } catch (Exception ex) { return(new ApiResponse <int> { code = 0, message = "Mobile Number Already Exist" }); } return(new ApiResponse <int> { code = 1, message = "Register Successfully" }); }
public async Task CreateValidAppUser() { var registrationVm = new AppUserRegistration(1, "Nicholas", "Barger", "*****@*****.**", "Passw0rd!"); registrationVm.PhoneNumber = "239-216-3766"; var mockedDb = new Mock <AppUserContext>(); var service = new AppUserService(_mapper, mockedDb.Object, _jwtService, _logger); var user = await service.Create(registrationVm); Assert.True(user.Id > 0); }
public async Task <AppUser> Create(AppUserRegistration model) { var user = _mapper.Map <AppUser>(model); // create tenant var tenant = new Tenant(model.OrganizationName); tenant = await _tenantService.Create(tenant); // assign tenant id to user user.TenantId = tenant.Id; // hash password user.PasswordHash = Encryption.HashPassword(model.Password); await _db.AppUsers.AddAsync(user); await _db.SaveChangesAsync(); return(user); }