Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar65
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
Нурбек Созоев
webinar65
Commits
28aaeb02
Commit
28aaeb02
authored
Jun 27, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил форму входа (Login)
parent
2040f456
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
6 deletions
+92
-6
AccountController.cs
webinar65/Controllers/AccountController.cs
+49
-0
HomeController.cs
webinar65/Controllers/HomeController.cs
+4
-6
LoginViewModel.cs
webinar65/ViewModels/LoginViewModel.cs
+15
-0
Login.cshtml
webinar65/Views/Account/Login.cshtml
+24
-0
No files found.
webinar65/Controllers/AccountController.cs
0 → 100644
View file @
28aaeb02
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
webinar65.Models
;
using
webinar65.ViewModels
;
namespace
webinar65.Controllers
{
public
class
AccountController
:
Controller
{
private
UserManager
<
User
>
_userManager
;
private
SignInManager
<
User
>
_signInManager
;
public
AccountController
(
UserManager
<
User
>
userManager
,
SignInManager
<
User
>
signInManager
)
{
_userManager
=
userManager
;
_signInManager
=
signInManager
;
}
[
HttpGet
]
public
IActionResult
Login
(
string
returnUrl
)
{
ViewBag
.
returnUrl
=
returnUrl
;
return
View
();
}
[
HttpPost
]
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
model
,
string
returnUrl
)
{
if
(
ModelState
.
IsValid
)
{
var
user
=
await
_userManager
.
FindByEmailAsync
(
model
.
Email
);
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
user
.
UserName
,
model
.
Password
,
false
,
false
);
if
(
result
.
Succeeded
)
return
Redirect
(
returnUrl
??
"/"
);
ModelState
.
AddModelError
(
nameof
(
LoginViewModel
.
Email
),
"Invalid email or password"
);
}
return
View
(
model
);
}
}
}
webinar65/Controllers/HomeController.cs
View file @
28aaeb02
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Diagnostics
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
webinar65.Models
;
namespace
webinar65.Controllers
{
[
Authorize
]
public
class
HomeController
:
Controller
{
public
IActionResult
Index
()
...
...
webinar65/ViewModels/LoginViewModel.cs
0 → 100644
View file @
28aaeb02
using
System.ComponentModel.DataAnnotations
;
namespace
webinar65.ViewModels
{
public
class
LoginViewModel
{
[
Required
]
[
UIHint
(
"email"
)]
public
string
Email
{
get
;
set
;
}
[
Required
]
[
UIHint
(
"password"
)]
public
string
Password
{
get
;
set
;
}
}
}
webinar65/Views/Account/Login.cshtml
0 → 100644
View file @
28aaeb02
@model webinar65.ViewModels.LoginViewModel
@{
ViewBag.Title = "Login";
Layout = "_Layout";
}
<h2>Login</h2>
<div asp-validation-summary="All" class="text-danger"></div>
<form asp-action="Login" method="post">
<input type="hidden" name="returnUrl" value="@ViewBag.returnUrl"/>
<div class="form-group">
<label asp-for="Email">Email</label>
<input asp-for="Email" class="form-control"/>
</div>
<div class="form-group">
<label asp-for="Password">Password</label>
<input asp-for="Password" class="form-control"/>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
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