我正在使用 Entity Framework 6.0(代码优先)在 ASP.NET MVC4 中开发登录/注册系统,我想知道我应该如何正确处理 POST-s。
我的用户模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace Autokereskedes.Models
{
public class User
{
//Saját Kulcs
[Key]
public int UserId { set; get; }
//Külső kulcsok
//Model hivatkozások
public List<Reservation> Reservations { set; get; }
//Egyedi elemek
[Required]
[EmailAddress]
[StringLength(254)]
[Display(Name = "E-mail")]
public string Email { set; get; }
[Required]
[DataType(DataType.Password)]
[StringLength(100,MinimumLength=4)]
[Display(Name = "Jelszó")]
public string Password { set; get; }
public string Phone { set; get; }
public Boolean Banned { set; get; }
public string Country { set; get; }
public string City { set; get; }
public string Street { set; get; }
public int? ZipCode { set; get; }
public DateTime RegistrationDate { set; get; }
public DateTime? LastLoginDate { set; get; }
public DateTime? PasswordChangedDate { set; get; }
}
}
还有我的登录功能:
[HttpPost]
public ActionResult LogIn(User user)
{
if (ModelState.IsValid)
{
if (IsUserDataValid(user.Email, user.Password))
{
FormsAuthentication.SetAuthCookie(user.Email, user.???)
}
}
return View();
}
我想根据登录表单中的复选框设置持久 cookie,但我的用户模型没有public Boolean StayLoggedIn;
属性,我也不希望这个选项存储在我的数据库中。我该如何处理?
我的登录表格:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true, "Sikertelen belépés, ellenőrizze adataid!");
<div>@Html.LabelFor(u => u.Email)</div>
<div class="input-control text">
@Html.TextBoxFor(u => u.Email, new { @placeholder = "Írja be az email címét"})
@Html.ValidationMessageFor(u => u.Email)
<button class="btn-clear"></button>
</div>
<div>@Html.LabelFor(u => u.Password)</div>
<div class="input-control password">
@Html.TextBoxFor(u => u.Password, new { @placeholder = "Írja be jelszavát" })
@Html.ValidationMessageFor(u => u.Password)
<button class="btn-reveal"></button>
</div>
<label class="input-control checkbox">
<input type="checkbox">
<span class="helper">Bejelentkezve marad</span>
</label>
<input type="submit" value="Bejelentkezés" />
}