Website Summary Files Commits Branches @commit @diff @stats
path: root / ExamTemplate / Web / Controllers / UserController.cs
diff options
context:
space:
mode:
Commit8f7dabf274b5e428fc32f19a3c8848eacab01090 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-05-07 11:59:29 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-05-07 11:59:29 +0300
Filesb738b66fa6621ed88b199e820702cae16422f9ba /ExamTemplate/Web/Controllers/UserController.cs
it-kariera-exam-template-8f7dabf274b5e428fc32f19a3c8848eacab01090.tar
it-kariera-exam-template-8f7dabf274b5e428fc32f19a3c8848eacab01090.tar.gz
it-kariera-exam-template-8f7dabf274b5e428fc32f19a3c8848eacab01090.zip
Parentbd2ebdd29e03425a8314a91b64a5943df83b7559 (diff)
Added view model validation for register and login
1 files changed, 6 insertions, 0 deletions
-rw-r--r--ExamTemplate/Web/Controllers/UserController.cs6
diff --git a/ExamTemplate/Web/Controllers/UserController.cs b/ExamTemplate/Web/Controllers/UserController.cs
index 4a22de7..622a616 100644
--- a/ExamTemplate/Web/Controllers/UserController.cs
+++ b/ExamTemplate/Web/Controllers/UserController.cs
@@ -29,6 +29,9 @@ namespace ExamTemplate.Web.Controllers
[Route("/Register")]
public async Task<IActionResult> Register(RegisterUserViewModel registerUserViewModel)
{
+ if (!ModelState.IsValid)
+ return View(registerUserViewModel);
+
RegisterUserServiceModel registerUserServiceModel = this._autoMapper.Map<RegisterUserServiceModel>(registerUserViewModel);
bool result = await this._userService.RegisterUserAsync(registerUserServiceModel);
@@ -50,6 +53,9 @@ namespace ExamTemplate.Web.Controllers
[Route("/Login")]
public async Task<IActionResult> Login(LoginUserViewModel loginUserViewModel)
{
+ if (!ModelState.IsValid)
+ return View(loginUserViewModel);
+
LoginUserServiceModel loginUserServiceModel = this._autoMapper.Map<LoginUserServiceModel>(loginUserViewModel);
bool result = await this._userService.LoginUserAsync(loginUserServiceModel);