public async Task <IActionResult> RegisterAsync([FromBody] User request) { if (request == null || String.IsNullOrEmpty(request.Username) || String.IsNullOrEmpty(request.Email) || String.IsNullOrEmpty(request.Password)) { return(BadRequest("Invalid client request")); } if (await _userService.GetUserByNameAsync(request.Username) != null || await _userService.GetUserByEmailAsync(request.Email) != null) { return(BadRequest("Invalid client request, not unique")); } var userDriveFso = await _fsoService.CreateFsoAsync("root", null, null, true, null); request.Id = Guid.NewGuid().ToString(); var claims = _userService.GetUserClaims(request); var accessToken = _tokenService.GenerateAccessToken(claims); var refreshToken = _tokenService.GenerateRefreshToken(); var hashPassword = BC.HashPassword(request.Password); request.Password = hashPassword; request.RefreshToken = refreshToken; request.RefreshTokenExpiryTime = DateTime.Now.AddDays(7); request.DriveId = userDriveFso.Id; await _userService.CreateUserAsync(request); return(Ok(new TokenApiModel(accessToken, refreshToken))); }
public async Task <IActionResult> UploadAsync() { var parentId = Request.Form["rootId"]; var root = await _fsoService.GetFsoByIdAsync(int.Parse(parentId)); var user = await _userService.GetUserFromPrincipalAsync(this.User); if (!await _fsoService.CheckOwnerAsync(root, user)) { return(Forbid()); } try { var files = Request.Form.Files; var result = new List <FsoDTO>(); foreach (var file in files) { var fileName = await _fsoService.CreateFileAsync(file, user); var fsoName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fso = await _fsoService.CreateFsoAsync(fsoName, fileName, file.Length, false, root.Id); result.Add(_fsoService.ToDTO(fso)); } return(new JsonResult(result)); } catch (Exception ex) { return(StatusCode(500, $"Internal server error : {ex}")); } }