private void SaveProfile(HttpContext context) { Nails.edmx.AppUsers u = this.GetNailsProdContext.AppUsers.First(o => o.ID == Common.UserID); if (string.IsNullOrEmpty(u.Password)) { context.Response.WriteError("Password not updated"); } else { string email = context.Request.Params["email"]; string first_name = context.Request.Params["first_name"]; string about = context.Request.Params["about"]; string location = context.Request.Params["location"]; string fn = context.Request.Params["fn"]; string website = context.Request.Params["website"]; string name = context.Request.Params["name"]; if (!string.IsNullOrEmpty(fn)) { Uri uri = new Uri(fn); string filename = uri.Segments.Last(); string fp = Path.Combine(Common.Temp, Common.UserID.ToString(), filename); string uploadedpath = Common.UploadedImagePath; FileInfo fInfo = new FileInfo(fp); string nfn = fInfo.Name; if (fInfo.DirectoryName != uploadedpath) { string dest = Path.Combine(uploadedpath, nfn); fInfo.MoveTo(dest); } u.Avatar = nfn; } u.Location = location; u.Email = email; u.FirstName = first_name; u.Website = website; u.Location = location; u.About = about; u.Name = name; GetNailsProdContext.SaveChanges(); CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = u.ID }), Common.DefaultPassword), false); CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { email = u.Email, name = u.Name, avatar = string.IsNullOrWhiteSpace(u.Avatar) ? null : Common.UploadedImageRelPath + u.Avatar }), false); } }
private void ResetPass(HttpContext context) { string email = context.Request.Params["email"]; Nails.edmx.AppUsers user = this.GetNailsProdContext.AppUsers.FirstOrDefault(o => o.Email == email); if (user != null) { SmtpClient client = new SmtpClient(); MailMessage mess = new MailMessage("*****@*****.**", email); string pass = Common.RandomString(Common.PassMinChars); mess.Body = string.Format(File.ReadAllText(context.Server.MapPath("resetpasstmpl.html")), user.Name, user.Email, pass); mess.Subject = "Password reset for your PinPolish account"; mess.IsBodyHtml = true; client.Send(mess); user.Password = Common.GetHash(pass); GetNailsProdContext.SaveChanges(); context.Response.Write("新密碼已發送到您的電子郵件地址"); } else { context.Response.Write("未註冊的電子郵件地址與我們的應用程序"); } }