Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
NewLifeProject
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Юнусов Ибрагим
NewLifeProject
Commits
f3393b50
Commit
f3393b50
authored
Jul 21, 2022
by
Юнусов Ибрагим
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Изменил дефолтную авторизацию на IdentityCore
parent
ae7d38b9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
73 deletions
+84
-73
AccountsController.cs
NewStores/Store/Controllers/AccountsController.cs
+36
-35
LoginViewModel.cs
NewStores/Store/ViewModels/Auths/LoginViewModel.cs
+4
-1
Login.cshtml
NewStores/Store/Views/Accounts/Login.cshtml
+22
-25
_Layout.cshtml
NewStores/Store/Views/Shared/_Layout.cshtml
+22
-12
No files found.
NewStores/Store/Controllers/AccountsController.cs
View file @
f3393b50
...
@@ -19,43 +19,44 @@ public class AccountsController : Controller
...
@@ -19,43 +19,44 @@ public class AccountsController : Controller
}
}
[
HttpGet
]
[
HttpGet
]
public
IActionResult
Login
()
public
IActionResult
Login
(
string
?
returnUrl
=
null
)
{
{
return
View
();
return
View
(
new
LoginViewModel
{
ReturnUrl
=
returnUrl
!});
}
[
HttpPost
]
[
ValidateAntiForgeryToken
]
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
model
)
{
try
{
if
(
ModelState
.
IsValid
)
{
var
user
=
await
_userManager
.
FindByEmailAsync
(
model
.
Email
);
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
user
,
model
.
Password
,
model
.
RememberMe
,
false
);
if
(
result
.
Succeeded
)
{
if
(!
string
.
IsNullOrWhiteSpace
(
model
.
ReturnUrl
)
&&
Url
.
IsLocalUrl
(
model
.
ReturnUrl
))
return
Redirect
(
model
.
ReturnUrl
);
return
RedirectToAction
(
"Index"
,
"Home"
);
}
ModelState
.
AddModelError
(
string
.
Empty
,
"Неверный логин или/и пароль"
);
return
View
(
model
);
}
}
// [HttpPost]
return
View
(
model
);
// [ValidateAntiForgeryToken]
}
// public async Task<IActionResult> Login(LoginViewModel model)
catch
(
Exception
e
)
// {
{
// try
ModelState
.
AddModelError
(
""
,
e
.
Message
);
// {
return
View
(
model
);
// if (ModelState.IsValid)
}
// {
}
// var user = _userRepository.GetUserByEmail(model.Email);
// if (user is not null)
// {
// if (user.Password.Equals(model.Password))
// {
// await AuthenticateAsync(user);
// return RedirectToAction("Index", "Home");
// }
// ModelState.AddModelError("", "пароль введен неверно");
// }
// else
// {
// ModelState.AddModelError("", "пользователь не найден");
// }
// }
//
// return View(model);
// }
// catch (Exception e)
// {
// Console.WriteLine(e);
// return View();
// }
// }
[
HttpGet
]
[
HttpGet
]
public
IActionResult
Register
()
public
IActionResult
Register
()
...
@@ -108,7 +109,7 @@ public class AccountsController : Controller
...
@@ -108,7 +109,7 @@ public class AccountsController : Controller
public
async
Task
<
IActionResult
>
Logout
()
public
async
Task
<
IActionResult
>
Logout
()
{
{
await
HttpContext
.
SignOutAsync
(
CookieAuthenticationDefaults
.
AuthenticationScheme
);
await
_signInManager
.
SignOutAsync
(
);
return
RedirectToAction
(
"Login"
);
return
RedirectToAction
(
"Login"
);
}
}
}
}
\ No newline at end of file
NewStores/Store/ViewModels/Auths/LoginViewModel.cs
View file @
f3393b50
...
@@ -7,6 +7,9 @@ public class LoginViewModel
...
@@ -7,6 +7,9 @@ public class LoginViewModel
[
Required
(
ErrorMessage
=
"Введите email"
)]
[
Required
(
ErrorMessage
=
"Введите email"
)]
public
string
Email
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Введите пароль"
)]
[
Required
(
ErrorMessage
=
"Введите пароль"
)]
public
string
Password
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
[
Display
(
Name
=
"Запомнить?"
)]
public
bool
RememberMe
{
get
;
set
;
}
public
string
ReturnUrl
{
get
;
set
;
}
}
}
\ No newline at end of file
NewStores/Store/Views/Accounts/Login.cshtml
View file @
f3393b50
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Store.ViewModels.Auths.LoginViewModel
@model Store.ViewModels.Auths.LoginViewModel
@{
<h2>Вход в приложение</h2>
ViewBag.Title = "Вход";
<form method="post" asp-controller="Accounts" asp-action="Login"
}
asp-route-returnUrl="@Model.ReturnUrl">
<div asp-validation-summary="ModelOnly"></div>
<h2>Вход на сайт</h2>
<a asp-action="Register" asp-controller="Accounts">Регистрация</a>
<form asp-action="Login" asp-controller="Accounts" asp-anti-forgery="true">
<div class="validation" asp-validation-summary="ModelOnly"></div>
<div>
<div>
<div class="form-group">
<label asp-for="Email"></label><br />
<label asp-for="Email">Введите Email</label>
<input asp-for="Email" />
<input type="text" asp-for="Email" />
<span asp-validation-for="Email"></span>
<span asp-validation-for="Email"></span>
</div>
</div>
<div class="form-group"
>
<div
>
<label asp-for="Password">Введите пароль</label
>
<label asp-for="Password"></label><br /
>
<input asp-for="Password" />
<input asp-for="Password" />
<span asp-validation-for="Password"></span>
<span asp-validation-for="Password"></span>
</div>
</div>
<div class="form-group">
<div>
<input type="submit" value="Войти" class="btn" />
<label asp-for="RememberMe"></label><br />
<input asp-for="RememberMe" />
</div>
</div>
<div>
<input type="submit" value="Войти" />
</div>
</div>
</form>
</form>
\ No newline at end of file
NewStores/Store/Views/Shared/_Layout.cshtml
View file @
f3393b50
...
@@ -25,23 +25,33 @@
...
@@ -25,23 +25,33 @@
<li
class=
"nav-item"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Home"
asp-action=
"Privacy"
>
Privacy
</a>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Home"
asp-action=
"Privacy"
>
Privacy
</a>
</li>
</li>
</ul>
</div>
<div
class=
"login_group"
>
@if (User.Identity.IsAuthenticated)
@if (User.Identity.IsAuthenticated)
{
{
<li
class=
"nav-item"
>
<p>
@User.Identity.Name
</p>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Accounts"
asp-action=
"Logout"
>
Выход
</a>
</li>
<form
method=
"post"
asp-controller=
"Accounts"
asp-action=
"Logout"
>
<input
class=
"nav-link text-dark"
type=
"submit"
value=
"Выход"
/>
</form>
}
}
else
else
{
{
<ul
class=
"navbar-nav flex-grow-1"
>
<li
class=
"nav-item"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Accounts"
asp-action=
"Login
"
>
Вход
</a>
<a
asp-controller=
"Accounts"
asp-action=
"Login"
class=
"nav-link text-dark
"
>
Вход
</a>
</li>
</li>
<li
class=
"nav-item"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Accounts"
asp-action=
"Register
"
>
Регистрация
</a>
<a
asp-controller=
"Accounts"
asp-action=
"Register"
class=
"nav-link text-dark
"
>
Регистрация
</a>
</li>
</li>
}
</ul>
</ul>
}
</div>
</div>
</div>
</div>
</nav>
</nav>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment