Exemplo n.º 1
0
 public static string Control(string name)
 {
     DatabaseContext db = new DatabaseContext();
     var user = (from s in db.Users where s.Email == name select s).FirstOrDefault();
     if (user != null)
         return user.PaymentId;
     else return "test";
 }
Exemplo n.º 2
0
        public string URLC(int id, string control, string t_id, string amount, [Bind(Include = "e-mail")]string email, string t_status, string md5)
        {
            string textToBeHashed = String.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}:{9}:{10}",
                                              Dotpay.PIN,
                                              id,
                                              control == null ? "" : control,
                                              t_id == null ? "" : t_id,
                                              amount == null ? "" : amount,
                                              email == null ? "" : email,
                                              "",
                                              "",
                                              "",
                                              "",
                                              t_status == null ? "" : t_status);

            if (Dotpay.IsValidNotyfication(textToBeHashed, md5) && double.Parse(amount, CultureInfo.InvariantCulture) == Premium.Amount) // TODO: IP
            {
                DatabaseContext db = new DatabaseContext();
                List<Models.Payment> lp = (from s in db.Payments where s.T_id == t_id select s).ToList();

                if (lp.Count == 1)
                {
                    lp[0].Status = int.Parse(t_status);
                    int UserID = lp[0].UserID;
                    Models.User us = (from s in db.Users where s.Id == UserID select s).FirstOrDefault();

                    if (lp[0].Status == 2)
                        us.AddDays(30);
                    else if (lp[0].Status == 4 || lp[0].Status == 5)
                        us.DeleteDays(30);
                }
                else
                {
                    List<Models.User> us = (from s in db.Users where s.PaymentId == control select s).ToList();
                    if (us.Count == 0)
                        return "";

                    db.Payments.Add(new Models.Payment() { T_id = t_id, Amount = double.Parse(amount, CultureInfo.InvariantCulture), Status = int.Parse(t_status), UserID = us[0].Id });
                }
                db.SaveChanges();
                return "OK";

            }
            else
            {
                return "";
            }
        }
Exemplo n.º 3
0
        public ActionResult Activate(string key)
        {
            DatabaseContext db = new DatabaseContext();

            var result = from u in db.Users
                    where u.ActivationKey == key// && u.Pass == pass
                    select u;

            if (result.Count() == 1)
            {
                User user = result.First();

                MembershipUser account = Membership.GetUser(user.Email);
                account.IsApproved = true;
                Membership.UpdateUser(account);

                FormsAuthentication.SetAuthCookie(account.Email, false /* createPersistentCookie */);

                return RedirectToAction("Index", "Home");
            }

            return View();
        }
Exemplo n.º 4
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.Email, model.Password, model.Email, null, null, false, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    MembershipUser account = Membership.GetUser(model.Email);

                    User user = new User();
                    user.Email = account.Email;
                    user.RegistrationDate = account.CreationDate;
                    user.PaymentId = Guid.NewGuid().ToString("N");
                    user.ActivationKey = Guid.NewGuid().ToString("N");

                    if (ModelState.IsValid)
                    {
                        DatabaseContext db = new DatabaseContext();

                        db.Users.Add(user);
                        db.SaveChanges();

                        Roles.AddUserToRole(account.Email, "User");

                        WebMail.SmtpServer = "smtp.gmail.com";
                        WebMail.EnableSsl = true;
                        WebMail.SmtpPort = 587;
                        WebMail.UserName = "******";
                        WebMail.Password = "******";
                        WebMail.Send(
                                account.Email,
                                "Aktywacja konta na Streameo",
                                "Witaj!<br /><br />" +
                                "Kliknij w poniższy link aby aktywować konto.<br /><br />" +
                                "<a href=\"" + Url.Action("Activate", "Account", new { key = user.ActivationKey }, Request.Url.Scheme) + "\">Aktywacja</a>"
                            );
                    }
                    else
                    {
                        Membership.DeleteUser(account.Email);
                    }

                    //FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);
                    return RedirectToAction("RegisterSuccess", "Account");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 5
0
        public ActionResult MyProfile()
        {
            DatabaseContext db = new DatabaseContext();

            var user = (from s in db.Users where s.Email == User.Identity.Name select s).First();

            user.PremiumEnd = DateTime.Now + new TimeSpan(10, 10, 10, 10);
            db.SaveChanges();

            ViewBag.AccountType = user.IsPremiumAccount();

            if (user.IsPremiumAccount())
            {
                ViewBag.EndDate = user.PremiumEnd.ToString();
            }

            return View();
        }
Exemplo n.º 6
0
        public ActionResult Handshake(string code)
        {
            bool flag = true;
            string clientId = "144618862327767";
            string clientSecret = "48af78235494ff833ed27d91d89a903d";

            //musimy wyslac zadanie w celu otrzymania access tokena
            string url = "https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}";

            string redirectUri = "http://localhost:1188/account/handshake/";

             WebRequest request = WebRequest.Create(string.Format(url, clientId, redirectUri, clientSecret, code));

            //przekonwertuj odpowiedz do utf8 i wyciagnij access tokena
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            StreamReader streamReader = new StreamReader(stream, encode);
            string accessToken = streamReader.ReadToEnd().Replace("access_token=", "");
            streamReader.Close();
            response.Close();

            var client = new FacebookClient(accessToken);
            dynamic me = client.Get("me");

            string email = me.email;
            string password = Membership.GeneratePassword(20, 6);

            DatabaseContext db = new DatabaseContext();

            var result = from u in db.Users
                         where u.Email == email
                         select u;

            if (result.Count() == 0)
            {
                MembershipCreateStatus createStatus;
                Membership.CreateUser(email, password, email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    MembershipUser account = Membership.GetUser(email);

                    User user = new User();
                    user.Email = account.Email;
                    user.RegistrationDate = account.CreationDate;
                    user.PaymentId = Guid.NewGuid().ToString("N");
                    user.ActivationKey = Guid.NewGuid().ToString("N");

                    if (ModelState.IsValid)
                    {
                        db.Users.Add(user);
                        db.SaveChanges();

                        Roles.AddUserToRole(account.Email, "User");
                    }
                    else
                    {
                        Membership.DeleteUser(account.Email);
                        flag = false;
                    }
                }
            }

            if (flag)
            {
                FormsAuthentication.SetAuthCookie(email, false /* createPersistentCookie */);
            }

            return RedirectToAction("Index", "Home");
        }