public async Task <IActionResult> Register(UserforRegister userForRegister) { userForRegister.Username = userForRegister.Username.ToLower(); if (await _repo.UserExist(userForRegister.Username)) { return(BadRequest("Username already exists!")); } var userToCreate = new User { Username = userForRegister.Username }; var createdUser = await _repo.Register(userToCreate, userForRegister.Password); return(StatusCode(201)); }
public async Task<IActionResult> ShipmentDetails([FromBody]UserforRegister userforRegister) { var userToCreate = new Shipment { Shipment_type = userforRegister.Shipment_type, Locality = userforRegister.Locality, Delivery_option = userforRegister.Delivery_option, Building_no = userforRegister.Building_no, Pickup_address = userforRegister.Pickup_address, L = userforRegister.L, B = userforRegister.B, H = userforRegister.H }; var createdUser = await _repo.ShipmentDetails(userToCreate); // userToCreate.SaveChanges() return StatusCode(200); }
public async Task <ActionResult <UserDto> > Register(UserforRegister userforRegister) { if (await UserExist(userforRegister.username)) { return(BadRequest("Username already taken")); } using var hmac = new HMACSHA512(); var user = new User { Name = userforRegister.username.ToLower(), PasswordHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(userforRegister.Password)) }; _context.Users.Add(user); await _context.SaveChangesAsync(); return(new UserDto { username = user.Name, Token = _tokenservice.CreateToken(user) }); }