public async Task<JsonResult> Signup(SignupViewModel model) { if(Session["SMSCode"].ToString() != model.Code) { return Json(new JsonErrorObj("验证码不正确", "code")); } using(MrCyContext ctx = new MrCyContext()) { ClientInfo client = new ClientInfo() { ClientId = (DateTime.Now.Year%100).ToString() + model.Mobile, ClientName = model.Mobile, LoginName = model.Mobile, LoginPwd = model.Password }; ctx.ClientInfo.Add(client); await ctx.SaveChangesAsync(); FormSignin(client); return Json(new JsonSucceedObj()); } }
private void FormSignin(ClientInfo c) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(c.ClientId, true, 60); string authTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName) { Value = authTicket, Expires = DateTime.Now.AddDays(1) }; Response.SetCookie(cookie); }