public async Task <ActionResult <User> > PostUser([FromBody] UserRequestBody user) { User errUser = new User { Email = "temp", Username = "******", }; bool duplicate = false; if (EmailExists(user.Email)) { errUser.Email = null; duplicate = true; } if (UsernameExists(user.Username)) { errUser.Username = null; duplicate = true; } if (duplicate) { return(errUser); } User postUser = new User { Username = user.Username, Email = user.Email, }; _context.Users.Add(postUser); await _context.SaveChangesAsync(); await InitUserAuth(user.Password, user.Email); return(CreatedAtAction("GetUser", new { id = postUser.Id }, user)); }
public async Task <IActionResult> PutPass(UserRequestBody user) { var idObj = _context.Users.SingleOrDefault(e => e.Email == user.Email); int uid = idObj.Id; var pObj = _context.UserAuths.SingleOrDefault(e => e.UserId == uid); if (pObj.Password != user.Username) { return(NotFound()); } _context.UserAuths.Remove(pObj); UserAuth tmp = new UserAuth { Password = user.Password, UserId = uid }; _context.UserAuths.Add(tmp); await _context.SaveChangesAsync(); return(Ok()); }