Skip to content

Commit

Permalink
Merge pull request #154 from xdorro/thuyet
Browse files Browse the repository at this point in the history
Thuyet
  • Loading branch information
thuyetbn authored Aug 26, 2021
2 parents 35bb19f + ec75a89 commit e8e4370
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 180 deletions.
1 change: 0 additions & 1 deletion Backend/Areas/Admin/Views/Accounts/ProfileAccount.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@
$("#Id").val(res.BankAccountId);
$("#Name").val(res.Name);
}
})
},
post: function (bank) {
Expand Down
24 changes: 19 additions & 5 deletions Backend/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,14 @@ public ActionResult Login()
return View();
}

[HttpPost]
public ActionResult CheckLogin(string email, string password)
{
var errors = new Dictionary<string, string>();
var obj = accounts.Get(x => x.Email == email).FirstOrDefault();



if (Utils.IsNullOrEmpty(obj))
{
errors.Add("Email", "Email is not exists!");
Expand Down Expand Up @@ -274,7 +277,7 @@ public ActionResult CheckLogin(string email, string password)
}, JsonRequestBehavior.AllowGet);
}

if (!password.Equals(obj.Password))
if (!Utils.ValidatePassword(password,obj.Password))
{
obj.AttemptLogin++;
accounts.Update(obj);
Expand Down Expand Up @@ -346,13 +349,15 @@ public ActionResult Register()
{
return View();
}

[HttpPost]
public ActionResult CheckRegister(RegisterViewModel register)
{
var errors = new Dictionary<string, string>();
var additionCheck = true;
IRepository<Accounts> users = new Repository<Accounts>();



foreach (var k in ModelState.Keys)
foreach (var err in ModelState[k].Errors)
{
Expand Down Expand Up @@ -381,18 +386,27 @@ public ActionResult CheckRegister(RegisterViewModel register)
data = errors
}, JsonRequestBehavior.AllowGet);


var account = new Accounts
{
Name = register.Name,
Email = register.Email,
Password = register.Password,
Password = Utils.HashPassword(register.Password),
NumberId = register.NumberId,
Phone = register.Phone,
AttemptLogin = 0,
RoleId = 3,
Birthday = DateTime.Parse("1970-01-01"),
Status = ((int) AccountStatus.Actived)
};

users.Add(account);
if (users.Add(account) == false)
{
return Json(new
{
statusCode = 404,
message = "Error",
}, JsonRequestBehavior.AllowGet);
}
return Json(new
{
statusCode = 200,
Expand Down
129 changes: 77 additions & 52 deletions Backend/Views/Home/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,68 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Vora - Saas Bootstrap Admin Dashboard</title>
<title>Register</title>
<!-- Favicon icon -->
<link rel="icon" type="image/png" sizes="16x16" href="~/Content/images/favicon.png">
<link href="~/Content/vendor/sweetalert2/dist/sweetalert2.min.css" rel="stylesheet">
<link href="~/Content/css/style.css" rel="stylesheet">

</head>

<body class="h-100">
<div class="authincation h-100">
<div class="container h-100">
<div class="row justify-content-center h-100 align-items-center">
<div class="col-md-6">
<div class="authincation-content">
<div class="row no-gutters">
<div class="col-xl-12">
<div class="auth-form">
<h2 class="text-center mb-4 text-white text-uppercase">Sign up your account</h2>
<form id="formData">
<div class="form-group">
<label class="mb-1 text-white">
Name
</label>
<input type="text" id="Name" name="Name" class="form-control" placeholder="Name">
<div class="authincation h-100">
<div class="container h-100">
<div class="row justify-content-center h-100 align-items-center">
<div class="col-md-6">
<div class="authincation-content">
<div class="row no-gutters">
<div class="col-xl-12">
<div class="auth-form">
<h2 class="text-center mb-4 text-white text-uppercase">Sign up your account</h2>
<form id="formData">
<div class="form-group">
<label class="mb-1 text-white">
Name
</label>
<input type="text" id="Name" name="Name" class="form-control" placeholder="Name">
</div>
<div class="form-group">
<label class="mb-1 text-white">
Email
</label>
<input type="email" id="Email" name="Email" class="form-control" placeholder="[email protected]">
</div>
<div class="form-group">
<label class="mb-1 text-white">
ID Card
</label>
<input type="text" id="NumberId" name="NumberId" class="form-control" placeholder="123456789">
</div>
<div class="form-group">
<label class="mb-1 text-white">
Phone
</label>
<input type="text" id="Phone" name="Phone" class="form-control" placeholder="0987654321">
</div>
<div class="form-group">
<label class="mb-1 text-white">
Password
</label>
<input type="password" id="Password" name="Password" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<label class="mb-1 text-white">
Confirm Password
</label>
<input type="password" id="RePassword" name="RePassword" class="form-control" placeholder="Confirm Password">
</div>
<div class="text-center mt-4">
<button type="submit" class="btn btn-block btn-pill btn-outline-light btn-rounded">Sign me up</button>
</div>
</form>
<div class="new-account mt-3">
<p class="text-white">Already have an account? <a class="text-white" href="@Url.Action("Login", "Home")">Sign in</a></p>
</div>
<div class="form-group">
<label class="mb-1 text-white">
Email
</label>
<input type="email" id="Email" name="Email" class="form-control" placeholder="[email protected]">
</div>
<div class="form-group">
<label class="mb-1 text-white">
Password
</label>
<input type="password" id="Password" name="Password" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<label class="mb-1 text-white">
Confirm Password
</label>
<input type="password" id="RePassword" name="RePassword" class="form-control" placeholder="Confirm Password">
</div>
<div class="text-center mt-4">
<button type="submit" class="btn btn-block btn-pill btn-outline-light btn-rounded">Sign me up</button>
</div>
</form>
<div class="new-account mt-3">
<p class="text-white">Already have an account? <a class="text-white" href="@Url.Action("Login", "Home")">Sign in</a></p>
</div>
</div>
</div>
Expand All @@ -65,18 +79,19 @@
</div>
</div>
</div>
</div>

<!--**********************************
Scripts
***********************************-->
<!-- Required vendors -->
<script src="~/Content/vendor/global/global.min.js" type="text/javascript"></script>
<script src="~/Content/vendor/bootstrap-select/dist/js/bootstrap-select.min.js" type="text/javascript"></script>
<script src="~/Content/js/custom.js" type="text/javascript"></script>
<script src="~/Content/js/dlabnav-init.js" type="text/javascript"></script>
<script src="~/Content/vendor/jquery-validation/jquery.validate.min.js"></script>
<script>
<!--**********************************
Scripts
***********************************-->
<!-- Required vendors -->
<script src="~/Content/vendor/sweetalert2/dist/sweetalert2.min.js"></script>
<script src="~/Content/vendor/global/global.min.js" type="text/javascript"></script>
<script src="~/Content/vendor/bootstrap-select/dist/js/bootstrap-select.min.js" type="text/javascript"></script>
<script src="~/Content/js/custom.js" type="text/javascript"></script>
<script src="~/Content/js/dlabnav-init.js" type="text/javascript"></script>
<script src="~/Content/vendor/jquery-validation/jquery.validate.min.js"></script>

<script>
let validator = $("#formData").validate({
rules: {
Name: {
Expand All @@ -86,6 +101,14 @@ Scripts
required: true,
email: true,
},
NumberId: {
required: true,
minlength: 9,
},
Phone: {
required: true,
minlength: 10,
},
Password: {
required: true,
minlength: 6,
Expand Down Expand Up @@ -115,12 +138,14 @@ Scripts
data: {
Name: $("#Name").val(),
Email: $("#Email").val(),
Phone: $("#Phone").val(),
NumberId: $("#NumberId").val(),
Password: $("#Password").val(),
RePassword: $("#RePassword").val()
},
success: function (res) {
if (res.statusCode === 200) {
window.location.replace(`/${res.url}`);
swal("Register Success !!", "You clicked the button return Login !!", "success").then(() => { window.location.replace(`/${res.url}`) });
} else {
validator.showErrors(res.data);
}
Expand Down
14 changes: 14 additions & 0 deletions OnlineBanking.DAL/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,19 @@ public static string RandomString(int length)
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
private static string GetRandomSalt()
{
return BCrypt.Net.BCrypt.GenerateSalt(12);
}

public static string HashPassword(string password)
{
return BCrypt.Net.BCrypt.HashPassword(password, GetRandomSalt());
}

public static bool ValidatePassword(string password, string correctHash)
{
return BCrypt.Net.BCrypt.Verify(password, correctHash);
}
}
}
4 changes: 3 additions & 1 deletion OnlineBanking.DAL/DataMapping/Accounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public class Accounts : BaseModel
[Required] [EmailAddress] public string Email { get; set; }

[Required]
[StringLength(24, MinimumLength = 6)]
[MinLength(6)]
public string Password { get; set; }

[RegularExpression(@"^0[0-9]{9,14}$",ErrorMessage = "Phone number is not in the correct format")]
[Required] public string Phone { get; set; }

public string Address { get; set; }
Expand All @@ -30,6 +31,7 @@ public class Accounts : BaseModel

[DefaultValue(RoleStatus.User)] public int RoleId { get; set; }

[StringLength(24, MinimumLength = 9)]
[Required] public string NumberId { get; set; }

[DefaultValue(0)] public int AttemptLogin { get; set; }
Expand Down
Loading

0 comments on commit e8e4370

Please sign in to comment.