-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...rm/trading_backend/src/main/java/com/thuta/trading_backend/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.thuta.trading_backend.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.thuta.trading_backend.entity.User; | ||
import com.thuta.trading_backend.response.DataResponse; | ||
import com.thuta.trading_backend.service.auth.IAuthService; | ||
|
||
@RestController | ||
@RequestMapping("${api.prefix}/auth") | ||
public class AuthController { | ||
|
||
@Autowired | ||
private IAuthService authService; | ||
|
||
@PostMapping("/signup") | ||
public ResponseEntity<DataResponse> register( | ||
@RequestBody User user) throws Exception { | ||
try { | ||
User savedUser = authService.register(user); | ||
return ResponseEntity.ok(new DataResponse("signup success", savedUser)); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(new DataResponse(e.getMessage(), null)); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...rm/trading_backend/src/main/java/com/thuta/trading_backend/controller/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.thuta.trading_backend.controller; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("${api.prefix}") | ||
public class HomeController { | ||
@GetMapping | ||
public String home() { | ||
return "Welcome to trading platform"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...latform/trading_backend/src/main/java/com/thuta/trading_backend/entity/TwoFactorAuth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.thuta.trading_backend.entity; | ||
|
||
import com.thuta.trading_backend.enums.VERIFICATION_TYPE; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* Two Factor Authentication | ||
*/ | ||
@Data | ||
public class TwoFactorAuth { | ||
private boolean isEnabled = false; | ||
private VERIFICATION_TYPE sendTo; | ||
} |
34 changes: 34 additions & 0 deletions
34
...trading_platform/trading_backend/src/main/java/com/thuta/trading_backend/entity/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.thuta.trading_backend.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.thuta.trading_backend.enums.USER_ROLE; | ||
|
||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Data; | ||
|
||
/** | ||
* User Entity | ||
*/ | ||
@Entity | ||
@Data | ||
public class User { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String fullName; | ||
|
||
private String email; | ||
|
||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) | ||
private String password; | ||
|
||
@Embedded | ||
private TwoFactorAuth twoFactorAuth = new TwoFactorAuth(); | ||
|
||
private USER_ROLE role = USER_ROLE.ROLE_CUSTOMER; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ing_platform/trading_backend/src/main/java/com/thuta/trading_backend/enums/USER_ROLE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.thuta.trading_backend.enums; | ||
|
||
/** | ||
* User Role Enum | ||
*/ | ||
public enum USER_ROLE { | ||
ROLE_ADMIN, | ||
ROLE_CUSTOMER | ||
} |
9 changes: 9 additions & 0 deletions
9
...form/trading_backend/src/main/java/com/thuta/trading_backend/enums/VERIFICATION_TYPE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.thuta.trading_backend.enums; | ||
|
||
/** | ||
* Verification Type Enum | ||
*/ | ||
public enum VERIFICATION_TYPE { | ||
MOBILE, | ||
} |
9 changes: 9 additions & 0 deletions
9
...rm/trading_backend/src/main/java/com/thuta/trading_backend/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.thuta.trading_backend.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.thuta.trading_backend.entity.User; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...atform/trading_backend/src/main/java/com/thuta/trading_backend/response/DataResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.thuta.trading_backend.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
/** | ||
* Data Response Object | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
public class DataResponse { | ||
private String message; | ||
private Object data; | ||
} |
32 changes: 32 additions & 0 deletions
32
...orm/trading_backend/src/main/java/com/thuta/trading_backend/service/auth/AuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.thuta.trading_backend.service.auth; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.thuta.trading_backend.entity.User; | ||
import com.thuta.trading_backend.repository.UserRepository; | ||
|
||
@Service | ||
public class AuthService implements IAuthService { | ||
@Autowired | ||
private UserRepository userRepo; | ||
|
||
@Autowired | ||
private PasswordEncoder passwordEncoder; | ||
|
||
@Override | ||
public User register(User user) throws Exception { | ||
try { | ||
User newUser = new User(); | ||
newUser.setFullName(user.getFullName()); | ||
newUser.setEmail(user.getEmail()); | ||
newUser.setPassword(passwordEncoder.encode(user.getPassword())); | ||
|
||
User savedUser = userRepo.save(newUser); | ||
return savedUser; | ||
} catch (Exception e) { | ||
throw new Exception("Something went wrong at signup"); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rm/trading_backend/src/main/java/com/thuta/trading_backend/service/auth/IAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.thuta.trading_backend.service.auth; | ||
|
||
import com.thuta.trading_backend.entity.User; | ||
|
||
public interface IAuthService { | ||
User register(User user) throws Exception; | ||
} |