Exemplo n.º 1
0
        private void RequestInvite(HttpContext context)
        {
            string email = context.Request.Params["email"];

            Nails.edmx.AppUsers user = this.GetNailsProdContext.AppUsers.FirstOrDefault(o => o.Email == email);
            if (user == null)
            {
                user       = new Nails.edmx.AppUsers();
                user.Email = email;
                SmtpClient  client = new SmtpClient();
                string      hash   = Common.GetString(Common.Hash.ComputeString(Guid.NewGuid().ToString()).GetBytes());
                MailMessage mess   = new MailMessage("*****@*****.**", email);
                mess.Body       = string.Format(File.ReadAllText(context.Server.MapPath("signuptmpl.html")), string.Format("<a href='{0}{1}?s={2}'>Click here to register</a>", Common.Domain, Common.InviteUrl, hash));
                mess.Subject    = "Sign Up for PinPolish";
                mess.IsBodyHtml = true;
                client.Send(mess);
                user.Invite = hash;
                this.GetNailsProdContext.AppUsers.AddObject(user);
                this.GetNailsProdContext.SaveChanges();
                context.Response.Write("An Invitation has been sent to your email address.Please follow the instructions to complete the registration");
            }
            else
            {
                context.Response.Write("The email address has already been registered with our application");
            }
        }
Exemplo n.º 2
0
        private void ChangePassword(HttpContext context)
        {
            string pass = context.Request.Params["pass"];

            if (!string.IsNullOrEmpty(pass))
            {
                Nails.edmx.AppUsers u = this.GetNailsProdContext.AppUsers.First(o => o.ID == Common.UserID);
                IHash      hash       = Common.Hash;
                HashResult res        = hash.ComputeString(pass);
                u.Password = Common.GetString(res.GetBytes());
                this.GetNailsProdContext.SaveChanges();
                context.Response.Write("Password has been updated");
            }
        }
Exemplo n.º 3
0
        private void Invite(HttpContext context)
        {
            string invite = context.Request.QueryString["s"];

            if (!string.IsNullOrEmpty(invite))
            {
                Nails.edmx.AppUsers au = GetNailsProdContext.AppUsers.FirstOrDefault(o1 => o1.Invite == invite);
                if (au != null)
                {
                    CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = au.ID }), Common.DefaultPassword), false);
                    CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { email = au.Email, name = au.Name, avatar = string.IsNullOrWhiteSpace(au.Avatar) ? null : Common.UploadedImageRelPath + au.Avatar }), false);
                    context.Response.Redirect("~/home#settings", false);
                }
            }
        }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
        private void ValidateContributor(HttpContext context)
        {
            string contributor = context.Request.Params["contributor"];

            Nails.edmx.AppUsers user = this.GetNailsProdContext.AppUsers.FirstOrDefault(o => o.Email == contributor || o.Name == contributor);
            if (user != null)
            {
                context.Response.Write(JsonConvert.SerializeObject(new
                {
                    user.Email,
                    user.Avatar,
                    user.FirstName,
                    user.Name
                }));
            }
            else
            {
                context.Response.WriteError("User does not exist");
            }
        }
Exemplo n.º 6
0
        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("未註冊的電子郵件地址與我們的應用程序");
            }
        }