-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(User) : add regex class and exception
* feat(User) : add regex class and exception * feat(User) : add regex method in regeister api * feat(User) : add reset Password api * fix(User) : add reset Password api
- Loading branch information
1 parent
97b3e8d
commit 1299b55
Showing
19 changed files
with
249 additions
and
44 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,71 @@ | ||
using System.Security.Claims; | ||
using AnalysisData.Exception; | ||
using AnalysisData.Services; | ||
using AnalysisData.UserManage.LoginModel; | ||
using AnalysisData.UserManage.RegisterModel; | ||
using AnalysisData.UserManage.ResetPasswordModel; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AnalysisData.Controllers; | ||
|
||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class UserController : ControllerBase | ||
{ | ||
private readonly IUserService _userService; | ||
private readonly IPermissionService _permissionService; | ||
|
||
public UserController(IUserService userService,IPermissionService permissionService) | ||
public UserController(IUserService userService, IPermissionService permissionService) | ||
{ | ||
_userService = userService; | ||
_permissionService = permissionService; | ||
} | ||
|
||
[HttpPost("login")] | ||
public IActionResult Login([FromBody] UserLoginModel userLoginModel) | ||
{ | ||
var user = _userService.Login(userLoginModel); | ||
return Ok(new { user.Result.FirstName , user.Result.LastName , user.Result.ImageURL }); | ||
return Ok(new { user.Result.FirstName, user.Result.LastName, user.Result.ImageURL }); | ||
} | ||
|
||
[Authorize(Roles = "admin")] | ||
[HttpPost("register")] | ||
public async Task<IActionResult> Register([FromBody] UserRegisterModel userRegisterModel) | ||
{ | ||
var check = await _userService.Register(userRegisterModel); | ||
var check = await _userService.Register(userRegisterModel); | ||
if (check) | ||
{ | ||
return Ok("success"); | ||
} | ||
|
||
return NotFound("not success"); | ||
return BadRequest("not success"); | ||
} | ||
|
||
|
||
[HttpGet("permissions")] | ||
public IActionResult GetPermissions() | ||
{ | ||
var userClaims = User; | ||
var permission = _permissionService.GetPermission(userClaims); | ||
return Ok(new { permission }); | ||
var username = userClaims.FindFirstValue("username"); | ||
var firstName = userClaims.FindFirstValue("firstname"); | ||
var lastName = userClaims.FindFirstValue("lastname"); | ||
return Ok(new { username, firstName, lastName, permission }); | ||
} | ||
|
||
|
||
[HttpPost("reset-password")] | ||
public async Task<IActionResult> ResetPassword([FromBody] ResetPasswordModel resetPasswordModel) | ||
{ | ||
var userClaim = User; | ||
var check = await _userService.ResetPassword(userClaim, resetPasswordModel.NewPassword, | ||
resetPasswordModel.ConfirmPassword); | ||
if (check) | ||
{ | ||
return Ok("success"); | ||
} | ||
|
||
return BadRequest("not success"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
AnalysisData/AnalysisData/Exception/InvalidEmailFormatException.cs
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,8 @@ | ||
namespace AnalysisData.Exception; | ||
|
||
public class InvalidEmailFormatException : System.Exception | ||
{ | ||
public InvalidEmailFormatException() : base(Resources.InvalidEmailFormatException) | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
AnalysisData/AnalysisData/Exception/InvalidPasswordFormatException.cs
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,8 @@ | ||
namespace AnalysisData.Exception; | ||
|
||
public class InvalidPasswordFormatException : System.Exception | ||
{ | ||
public InvalidPasswordFormatException() : base(Resources.InvalidPasswordFormatException) | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
AnalysisData/AnalysisData/Exception/InvalidPhoneNumberFormatException.cs
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,8 @@ | ||
namespace AnalysisData.Exception; | ||
|
||
public class InvalidPhoneNumberFormatException : System.Exception | ||
{ | ||
public InvalidPhoneNumberFormatException() : base(Resources.InvalidPhoneNumberFormatException) | ||
{ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
namespace AnalysisData.Exception; | ||
using System; | ||
|
||
public class UserNotFoundException : Exception | ||
{ | ||
public UserNotFoundException() : base(Resources.UserNotFoundException) | ||
{ | ||
} | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace AnalysisData.Services; | ||
|
||
public interface IRegexService | ||
{ | ||
public void EmailCheck(string email); | ||
public void PasswordCheck(string password); | ||
public void PhoneNumberCheck(string phoneNumber); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Text.RegularExpressions; | ||
using AnalysisData.Exception; | ||
using AnalysisData.UserManage.Model; | ||
|
||
namespace AnalysisData.Services; | ||
|
||
public class RegexService : IRegexService | ||
{ | ||
public void EmailCheck(string email) | ||
{ | ||
string pattern = RegexPatterns.EmailRegex; | ||
|
||
Regex regex = new Regex(pattern); | ||
bool isMatch = regex.IsMatch(email); | ||
if (!isMatch) | ||
{ | ||
throw new InvalidEmailFormatException(); | ||
} | ||
} | ||
|
||
public void PhoneNumberCheck(string phoneNumber) | ||
{ | ||
string pattern = RegexPatterns.PhoneNumberRegex; | ||
Regex regex = new Regex(pattern); | ||
bool isMatch = regex.IsMatch(phoneNumber); | ||
if (!isMatch) | ||
{ | ||
throw new InvalidPhoneNumberFormatException(); | ||
} | ||
} | ||
|
||
public void PasswordCheck(string password) | ||
{ | ||
string pattern = RegexPatterns.PasswordRegex; | ||
Regex regex = new Regex(pattern); | ||
bool isMatch = regex.IsMatch(password); | ||
if (!isMatch) | ||
{ | ||
throw new InvalidPasswordFormatException(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.