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
Hide 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]
[
HttpPost
]
// [ValidateAntiForgeryToken]
[
ValidateAntiForgeryToken
]
// public async Task<IActionResult> Login(LoginViewModel model)
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
model
)
// {
{
// try
try
// {
{
// if (ModelState.IsValid)
if
(
ModelState
.
IsValid
)
// {
{
// var user = _userRepository.GetUserByEmail(model.Email);
var
user
=
await
_userManager
.
FindByEmailAsync
(
model
.
Email
);
// if (user is not null)
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
// {
user
,
model
.
Password
,
model
.
RememberMe
,
false
);
// if (user.Password.Equals(model.Password))
// {
if
(
result
.
Succeeded
)
// await AuthenticateAsync(user);
{
// return RedirectToAction("Index", "Home");
if
(!
string
.
IsNullOrWhiteSpace
(
model
.
ReturnUrl
)
&&
Url
.
IsLocalUrl
(
model
.
ReturnUrl
))
// }
return
Redirect
(
model
.
ReturnUrl
);
// ModelState.AddModelError("", "пароль введен неверно");
// }
return
RedirectToAction
(
"Index"
,
"Home"
);
// else
}
// {
// ModelState.AddModelError("", "пользователь не найден");
ModelState
.
AddModelError
(
string
.
Empty
,
"Неверный логин или/и пароль"
);
// }
// }
return
View
(
model
);
//
}
// return View(model);
// }
return
View
(
model
);
// catch (Exception e)
}
// {
catch
(
Exception
e
)
// Console.WriteLine(e);
{
// return View();
ModelState
.
AddModelError
(
""
,
e
.
Message
);
// }
return
View
(
model
);
// }
}
}
[
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>
<div>
<label asp-for="Email"></label><br />
<a asp-action="Register" asp-controller="Accounts">Регистрация</a>
<input asp-for="Email" />
<span asp-validation-for="Email"></span>
<form asp-action="Login" asp-controller="Accounts" asp-anti-forgery="true">
</div>
<div class="validation" asp-validation-summary="ModelOnly"></div>
<div>
<div>
<label asp-for="Password"></label><br />
<div class="form-group">
<input asp-for="Password" />
<label asp-for="Email">Введите Email</label>
<span asp-validation-for="Password"></span>
<input type="text" asp-for="Email" />
</div>
<span asp-validation-for="Email"></span>
<div>
</div>
<label asp-for="RememberMe"></label><br />
<div class="form-group">
<input asp-for="RememberMe" />
<label asp-for="Password">Введите пароль</label>
</div>
<input asp-for="Password" />
<div>
<span asp-validation-for="Password"></span>
<input type="submit" value="Войти" />
</div>
</div>
<div class="form-group">
<input type="submit" value="Войти" class="btn" />
</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>
@if (User.Identity.IsAuthenticated)
</ul>
{
</div>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Accounts"
asp-action=
"Logout"
>
Выход
</a>
<div
class=
"login_group"
>
</li>
@if (User.Identity.IsAuthenticated)
}
{
else
<p>
@User.Identity.Name
</p>
{
<form
method=
"post"
asp-controller=
"Accounts"
asp-action=
"Logout"
>
<input
class=
"nav-link text-dark"
type=
"submit"
value=
"Выход"
/>
</form>
}
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