Skip to content

Commit

Permalink
auth: add signup to API
Browse files Browse the repository at this point in the history
  • Loading branch information
darakeon committed Feb 18, 2024
1 parent 988cae9 commit c02a157
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 50 deletions.
30 changes: 18 additions & 12 deletions api/API/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ namespace DFM.API.Controllers
{
public class UsersController : BaseApiController
{
[HttpPost]
public IActionResult Login(String email, String password)
{
var model =
new UsersLoginModel
{
Email = email,
Password = password,
};
[HttpPost]
public IActionResult Login(String email, String password)
{
var model =
new UsersLoginModel
{
Email = email,
Password = password,
};

return json(() => new { ticket = model.LogOn() });
}
return json(() => new { ticket = model.LogOn() });
}

[HttpPost]
public IActionResult SignUp([FromBody] UsersSignUpModel model)
{
return json(model.SignUp);
}

[HttpPost]
public IActionResult Logout()
Expand All @@ -44,7 +50,7 @@ public IActionResult SaveSettings()
}

[HttpPost, Auth(AuthParams.IgnoreTFA)]
public IActionResult TFA(string code)
public IActionResult TFA(String code)
{
var model = new UserTFAModel(code);
return json(model.Validate);
Expand Down
17 changes: 0 additions & 17 deletions api/API/Models/BaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using DFM.API.Helpers.Global;
using DFM.API.Starters;
using DFM.BusinessLogic;
using DFM.BusinessLogic.Exceptions;
using DFM.BusinessLogic.Services;
using DFM.Generic;
using Microsoft.AspNetCore.Http;
using Error = DFM.BusinessLogic.Exceptions.Error;

namespace DFM.API.Models
{
Expand Down Expand Up @@ -40,21 +38,6 @@ public abstract class BaseModel
protected Boolean isUsingAccountsSigns => current.UseAccountsSigns;
protected Boolean moveCheckingEnabled => current.MoveCheck;

protected String login(String email, String password, Boolean rememberMe)
{
try
{
return current.Set(email, password, rememberMe);
}
catch (CoreError e)
{
if (e.Type == Error.DisabledUser)
outside.SendUserVerify(email);

throw;
}
}

protected void logout()
{
current.Clear();
Expand Down
3 changes: 0 additions & 3 deletions api/API/Models/MovesCreateModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DFM.BusinessLogic.Response;
using DFM.Entities.Enums;

namespace DFM.API.Models
{
Expand Down
13 changes: 12 additions & 1 deletion api/API/Models/UsersLoginModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using DFM.BusinessLogic.Exceptions;

namespace DFM.API.Models
{
Expand All @@ -15,7 +16,17 @@ internal class UsersLoginModel : BaseApiModel

internal string LogOn()
{
return login(Email, Password, RememberMe);
try
{
return current.Set(Email, Password, RememberMe);
}
catch (CoreError e)
{
if (e.Type == Error.DisabledUser)
outside.SendUserVerify(Email);

throw;
}
}
}
}
39 changes: 39 additions & 0 deletions api/API/Models/UsersSignUpModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.ComponentModel.DataAnnotations;
using DFM.BusinessLogic.Response;

namespace DFM.API.Models
{
public class UsersSignUpModel : BaseApiModel
{
[Required]
public String Email { get; set; }

[Required]
public String Password { get; set; }

[Required]
public Boolean AcceptedContract { get; set; }

[Required]
public String Language { get; set; }

[Required]
public String Timezone { get; set; }

internal void SignUp()
{
auth.SaveUser(
new SignUpInfo
{
Email = Email,
Password = Password,
AcceptedContract = AcceptedContract,
Language = Language,
TimeZone = Timezone,
RetypePassword = Password,
}
);
}
}
}
65 changes: 64 additions & 1 deletion api/postman/DFM.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,64 @@
},
"response": []
},
{
"name": "Users Signup",
"event": [
{
"listen": "test",
"script": {
"exec": [
"const json = pm.response.json()\r",
"\r",
"if (json.data) {\r",
" pm.collectionVariables.set(\"ticket\", json.data.ticket)\r",
"}\r",
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"var email_number = pm.collectionVariables.get(\"email_number\");\r",
"email_number = (email_number * 1) + 1;\r",
"pm.collectionVariables.set(\"email_number\", email_number);\r",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"Email\": \"{{test_user_email}}\",\r\n \"Password\": \"{{test_user_password}}\",\r\n \"AcceptedContract\": true,\r\n \"Language\": \"pt-BR\",\r\n \"Timezone\": \"UTC-03:00\"\r\n}\r\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/users/signup",
"host": [
"{{url}}"
],
"path": [
"users",
"signup"
]
}
},
"response": []
},
{
"name": "Users Login",
"event": [
Expand Down Expand Up @@ -785,7 +843,7 @@
},
{
"key": "test_user_email",
"value": "",
"value": "test{{email_number}}@dontflymoney.com",
"type": "string"
},
{
Expand All @@ -812,6 +870,11 @@
{
"key": "move_id",
"value": ""
},
{
"key": "email_number",
"value": "1",
"type": "string"
}
]
}
15 changes: 0 additions & 15 deletions site/MVC/Models/BaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ public abstract class BaseModel
protected Boolean isUsingAccountsSigns => current.UseAccountsSigns;
protected Boolean moveCheckingEnabled => current.MoveCheck;

protected String login(String email, String password, Boolean rememberMe)
{
try
{
return current.Set(email, password, rememberMe);
}
catch (CoreError e)
{
if (e.Type == Error.DisabledUser)
outside.SendUserVerify(email);

throw;
}
}

protected void logout()
{
current.Clear();
Expand Down
12 changes: 11 additions & 1 deletion site/MVC/Models/UsersLogOnModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ internal CoreError TryLogOn()

internal String LogOn()
{
return login(Email, Password, RememberMe);
try
{
return current.Set(Email, Password, RememberMe);
}
catch (CoreError e)
{
if (e.Type == Error.DisabledUser)
outside.SendUserVerify(Email);

throw;
}
}
}
}

0 comments on commit c02a157

Please sign in to comment.