예제 #1
0
        public ActionResult EmailConfirmed(ChangePassword chng)
        {
            string password = chng.password;

            if (TempData["id"] != null)
            {
                int          id      = int.Parse(TempData["id"].ToString());
                user         us      = context.users.Find(id);
                passwordHash hash    = new passwordHash();
                string       newpass = hash.CreateMd5(chng.password);
                var          user    = new user {
                    id = id, password = newpass
                };
                using (var db = new socialEntities())
                {
                    db.users.Attach(user);
                    db.Entry(user).Property(x => x.password).IsModified = true;
                    db.SaveChanges();
                }
                TempData["id"] = us.id;
                HttpCookie userId = new HttpCookie("id");
                userId.Value   = us.id.ToString();
                userId.Expires = DateTime.Now.AddHours(2);
                HttpContext.Response.SetCookie(userId);
                Session["User" + us.id] = us;
                return(Redirect("/Profile/Index/"));
            }
            return(View());
        }
예제 #2
0
        public JsonResult ChangeExPas()
        {
            int          id      = int.Parse(Request.Params["id"].ToString());
            passwordHash hash    = new passwordHash();
            user         us      = db.users.Find(id);
            string       pasEx   = Request.Params["pasEx"].ToString();
            string       pas     = Request.Params["pas"].ToString();
            string       pasConf = Request.Params["pasConf"].ToString();

            if (pas != pasConf)
            {
                object res = new object();
                res = (new {
                    error = "passwods are not same",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            else if (hash.CreateMd5(pasEx) != us.password)
            {
                object res = new object();
                res = (new
                {
                    error = "enter correct password",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var user = new user {
                    id = us.id, password = hash.CreateMd5(pas)
                };
                using (var db = new socialEntities())
                {
                    db.users.Attach(user);
                    db.Entry(user).Property(x => x.password).IsModified = true;
                    db.SaveChanges();
                }
                object res = new object();
                res = (new
                {
                    error = "success",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
0
        public async Task <ActionResult> Signup(userValidate valid)
        {
            List <string> dbo = new List <string>();

            foreach (Country ct in context.Countries)
            {
                dbo.Add(ct.Name);
            }
            SelectList list = new SelectList(dbo);

            ViewBag.countries = list;
            if (ModelState.IsValid)
            {
                foreach (user us in context.users)
                {
                    if (us.login == valid.login)
                    {
                        ViewBag.error = "that nickname already choosen please select other";
                        return(View());
                    }
                }
                passwordHash hash     = new passwordHash();
                string       hashable = hash.CreateMd5(valid.password.ToString());
                valid.password = hashable;
                user usr = new user();
                usr.name           = valid.name;
                usr.surname        = valid.surname;
                usr.login          = valid.login;
                usr.password       = valid.password;
                usr.country        = valid.country;
                usr.ConfirmedEmail = "false";
                usr.phone_number   = valid.phone;
                usr.age            = valid.age;
                if (Session["token"] != null)
                {
                    int inviterId = int.Parse(Session["token"].ToString());
                    usr.inviter_id   = inviterId;
                    Session["token"] = null;
                }
                usr.email = valid.Email;
                List <user> users = (from item in context.users where
                                     item.email == valid.Email && item.from_facebook != 1
                                     select item).ToList();
                if (users.Count > 0)
                {
                    ViewBag.error = "there is already have user with that Email";
                    return(View());
                }
                usr.birthdate = valid.birthdate;
                if (valid.birthdate > DateTime.Now)
                {
                    ViewBag.error = "false datetime";
                    return(View());
                }
                usr.gender = valid.gender;
                try
                {
                    HttpPostedFileBase file = Request.Files["Image"];
                    if (file != null && file.ContentLength > 0)
                    {
                        if (file.FileName.EndsWith(".png") || file.FileName.EndsWith(".jpg") || file.FileName.EndsWith(".jpeg"))
                        {
                            Int32  unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                            var    fileName      = Path.GetFileName(file.FileName);
                            string part          = "~/Content/Photos/" + (unixTimestamp + 1).ToString() + fileName;
                            var    path          = Path.Combine(Server.MapPath("~/Content/Photos/"), (unixTimestamp + 1).ToString() + fileName);
                            file.SaveAs(path);
                            usr.profile_photo = part;
                        }
                        else
                        {
                            ViewBag.error = "please updlad image with extenion .jpg .png .jpeg";
                            return(View());
                        }
                    }
                    else
                    {
                        if (valid.gender == "Male")
                        {
                            usr.profile_photo = "~/Content/Photos/avatarMale.png";
                        }
                        else
                        {
                            usr.profile_photo = "~/Content/Photos/avatarFemale.jpg";
                        }
                    }
                    this.context.users.Add(usr);
                    this.context.SaveChanges();
                    //email confirmation part
                    var         senderEmail   = new MailAddress("*****@*****.**", "Gambler");
                    var         receiverEmail = new MailAddress(valid.Email, "Receiver");
                    var         password      = "******";
                    MailMessage m             = new MailMessage(
                        new MailAddress("*****@*****.**", "Web Registration"),
                        new MailAddress(valid.Email));
                    m.Subject = "Email confirmation";
                    m.Body    = string.Format("Dear {0} <br/> Thank you for your registration, please click on the below link to complete your registration: <a href =\"{1}\">link</a>"
                                              , valid.name, Url.Action("Confirm", "ConfimEmail", new{ Token = usr.id, Email = usr.email }, Request.Url.Scheme));
                    m.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new NetworkCredential(senderEmail.Address, password)
                    };
                    {
                        smtp.Send(m);
                    }
                }
                catch (Exception e)
                {
                    ViewBag.error = e.Message;
                    return(View());
                }
                int iD = usr.id;
                Session["User" + iD.ToString()] = usr;
                TempData["id"] = usr.id;
                return(RedirectToAction("Index", "ConfimEmail"));
            }
            return(View());
        }