Esempio n. 1
0
        public ActionResult ForgotPassword(CertUser userModel)
        {
            var userDetails = db.CertUsers.Where(x => x.email == userModel.email).FirstOrDefault();

            if (userDetails != null)
            {
                MailMessage mailMessage = new MailMessage();
                mailMessage.To.Add(userModel.email);

                //Triba mail prominit, al radi ovako
                mailMessage.From = new MailAddress("*****@*****.**");

                mailMessage.Subject = "Do not forget your password this time!";
                mailMessage.Body    = "Username: "******"\nPassword:  "******"smtp.live.com", 587)
                {
                    EnableSsl = true,

                    Credentials = new System.Net.NetworkCredential("*****@*****.**", "Grf55psf")
                };
                smtpClient.Send(mailMessage);

                return(RedirectToAction("../Login/Index", new { flag = 1 }));
            }
            else
            {
                ViewBag.Message = "E-mail not sent";
                return(View("ForgotPassword", userModel));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> LoadBDokenAccount()
        {
            int id = (int)Session["userID"];

            CertUser addingNewAddress = (from n in db.CertUsers
                                         where n.certUserID == id
                                         select n).SingleOrDefault();

            string filepath = GetFilePath();

            if (filepath == "")
            {
                return(RedirectToAction("Index"));
            }

            addingNewAddress.beternumAddress = BDC.LoadFromKeystore(filepath);
            try
            {
                db.SaveChanges();
                await CheckBDokenBalance();
            }
            catch
            {
                return(RedirectToAction("Index", new { mssg = 2 }));
            }

            return(RedirectToAction("Index", new { mssg = 1 }));
        }
Esempio n. 3
0
        public async Task <ActionResult> CheckBDokenBalance()
        {
            try
            {
                int      sid    = (int)Session["userID"];
                CertUser result = (from r in db.CertUsers
                                   where r.certUserID == sid
                                   select r).SingleOrDefault();
                try
                {
                    BigInteger BigBalance = await BDC.CheckBalance(result.beternumAddress, "");

                    userBalance    = (decimal)BigBalance / 1000000000000000000;
                    result.balance = userBalance;
                }
                catch
                {
                    userBalance = -1;
                    return(RedirectToAction("Index", new { mssg = 5 }));
                }

                return(View("Index", result));
            }
            catch
            {
                return(Redirect("~/Login/Index"));
            }
        }
Esempio n. 4
0
        public async Task <ActionResult> Index(int mssg = 0)
        {
            try
            {
                int sid = (int)Session["userID"];
                switch (mssg)
                {
                case 1:
                    ViewBag.Message = "Account loaded successfully.";
                    break;

                case 2:
                    ViewBag.Message = "Error occured during account save.";
                    break;

                case 3:
                    ViewBag.Message = "Account created successfully.";
                    break;

                case 4:
                    ViewBag.Message = "Passphrase required.";
                    break;

                case 5:
                    ViewBag.Message = "Passphrase incorrect.";
                    break;

                case 6:
                    ViewBag.Message = "Amount set to 0, transaction cancelled.";
                    break;

                case 7:
                    ViewBag.Message = "Incorrect input, number is required.";
                    break;

                case 0:
                default:
                    ViewBag.Message = "";
                    break;
                }
                CertUser result = (from r in db.CertUsers
                                   where r.certUserID == sid
                                   select r).SingleOrDefault();
                await CheckBDokenBalance();

                result.balance = userBalance;
                BigInteger sellPrice = await BDC.GetSellPrice(result.beternumAddress);

                BigInteger buyPrice = await BDC.GetBuyPrice(result.beternumAddress);

                result.sellPrice = 1 / (decimal)sellPrice;
                result.buyPrice  = (decimal)buyPrice / 1000000000000000000;
                return(View(result));
            }
            catch
            {
                return(Redirect("~/Login/Index"));
            }
        }
Esempio n. 5
0
        public async Task <ActionResult> CreateBDokenAcc(System.Web.Mvc.FormCollection collection, int bdokenAccountFailed = 0)
        {
            try
            {
                int      id = (int)Session["userID"];
                CertUser addingNewAddress = (from n in db.CertUsers
                                             where n.certUserID == id
                                             select n).SingleOrDefault();
                string path = "";

                try
                {
                    string password = collection[2];
                    string retyped  = collection[3];
                    if (password == retyped)
                    {
                        path = GetDirPath();

                        if (path == "")
                        {
                            return(RedirectToAction("Index"));
                        }

                        addingNewAddress.beternumAddress = BDC.CreateNew(path, password);
                        try
                        {
                            db.SaveChanges();
                            await CheckBDokenBalance();
                        }
                        catch
                        {
                            return(RedirectToAction("Index", new { mssg = 2 }));
                        }
                        return(RedirectToAction("Index", new { mssg = 3 }));
                    }
                    else
                    {
                        return(RedirectToAction("CreateBDokenAcc", new { bdokenAccountFailed = 2 }));
                    }
                }
                catch
                {
                    return(RedirectToAction("CreateBDokenAcc", new { bdokenAccountFailed = 3 }));
                }
            }
            catch
            {
                return(Redirect("~/Login/Index"));
            }
        }
Esempio n. 6
0
        public JsonResult SaveUser(CertUser newCertUser)
        //public JsonResult SaveUser(CertUser newCertUser)
        {
            int state = 0;

            //string poruka = "amen chao";
            List <CertUser> ListOfUsers = connection.CertUsers.ToList();

            foreach (CertUser d in ListOfUsers)
            {
                if (newCertUser.email == d.email)
                {
                    state = 2;
                    return(Json(state, JsonRequestBehavior.AllowGet));
                }
                else if (newCertUser.username == d.username)
                {
                    state = 1;
                    return(Json(state, JsonRequestBehavior.AllowGet));
                }
            }

            //String password = Membership.GeneratePassword(8, 0);
            String password = Guid.NewGuid().ToString().Substring(0, 8);

            state = MessageSend(newCertUser.email, password, newCertUser.username);

            if (state == 0)
            {
                newCertUser.password        = password;
                newCertUser.beternumAddress = "";
                connection.CertUsers.Add(newCertUser);
                connection.SaveChanges();
            }
            else
            {
                state = 3;
                return(Json(state, JsonRequestBehavior.AllowGet));
            }


            return(Json(state, JsonRequestBehavior.AllowGet));
        }
Esempio n. 7
0
        public ActionResult Authorize(CertUser userModel)
        {
            using (BDEntities loginDB = new BDEntities())
            {
                var userDetails = loginDB.CertUsers.Where(x => x.username == userModel.username && x.password == userModel.password).FirstOrDefault();

                if (userDetails == null)
                {
                    Session["userID"]           = null;
                    userModel.LoginErrorMessage = "Wrong username or password !";

                    return(View("Index", userModel));
                }
                else
                {
                    Session["userID"] = userDetails.certUserID;
                    return(RedirectToAction("Index", "NavigationBar"));
                }
            }
        }
Esempio n. 8
0
        public ActionResult Index(string sortOrder = "", int insufficientFunds = 0, string searchString = "")
        {
            try
            {
                int      sid             = (int)Session["userID"];
                CertUser noBDokenAccount = (from u in db.CertUsers
                                            where u.certUserID == sid
                                            select u).SingleOrDefault();

                if (noBDokenAccount.beternumAddress.Equals(""))
                {
                    return(RedirectToAction("Index", "BDokenSettings"));
                }

                switch (insufficientFunds)
                {
                case 1:
                    ViewBag.Message = "Not enough gold, milord.";
                    break;

                case 2:
                    ViewBag.Message = "Incorrect passphrase.";
                    break;

                case 0:
                default:
                    ViewBag.Message = "";
                    break;
                }

                IQueryable <Video> videos = VideoSort(sortOrder, 1, searchString);

                return(View(videos.ToList()));
            }
            catch
            {
                return(Redirect("~/Login/Index"));
            }
        }
Esempio n. 9
0
        public async Task <ActionResult> BuySell(System.Web.Mvc.FormCollection collection)
        {
            if (preventResend != 1)
            {
                try
                {
                    int      sid    = (int)Session["userID"];
                    CertUser result = (from r in db.CertUsers
                                       where r.certUserID == sid
                                       select r).SingleOrDefault();
                    result.sellAmount = 0;
                    result.buyAmount  = 0;
                    result.bdokenPass = "";


                    string clickedButton = collection["hiddenClickedButton"];
                    result.bdokenPass = collection["passphrase"];
                    if (result.bdokenPass == "")
                    {
                        return(RedirectToAction("Index", new { mssg = 4 }));
                    }
                    if (!Decimal.TryParse(collection["hiddenAmount"], out decimal amount))
                    {
                        return(RedirectToAction("Index", new { mssg = 7 }));
                    }

                    if (clickedButton.Equals("Buy"))
                    {
                        result.buyAmount = amount;
                        if (result.buyAmount != 0)
                        {
                            try
                            {
                                await BDC.Buy(result.beternumAddress, result.bdokenPass, (BigInteger)result.buyAmount * 1000000000000000000);
                            }
                            catch
                            {
                                return(RedirectToAction("Index", new { mssg = 5 }));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Index", new { mssg = 6 }));
                        }
                    }
                    else if (clickedButton.Equals("Sell"))
                    {
                        result.sellAmount = amount;
                        if (result.sellAmount != 0)
                        {
                            try
                            {
                                await BDC.Sell(result.beternumAddress, result.bdokenPass, (BigInteger)(result.sellAmount * 1000000000000000000));
                            }
                            catch
                            {
                                return(RedirectToAction("Index", new { mssg = 5 }));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Index", new { mssg = 6 }));
                        }
                    }
                    else if (clickedButton.Equals("Donate"))
                    {
                        result.donateAmount = amount;
                        if (result.donateAmount != 0)
                        {
                            try
                            {
                                await BDC.BloodForTheBloodGod(result.beternumAddress, result.bdokenPass, (BigInteger)(result.donateAmount * 1000000000000000000));
                            }
                            catch
                            {
                                return(RedirectToAction("Index", new { mssg = 5 }));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Index", new { mssg = 6 }));
                        }
                    }

                    preventResend     = 1;
                    result.sellAmount = 0;
                    result.buyAmount  = 0;
                    BigInteger sellPrice = await BDC.GetSellPrice(result.beternumAddress);

                    BigInteger buyPrice = await BDC.GetBuyPrice(result.beternumAddress);

                    result.sellPrice = 1 / (decimal)sellPrice;
                    result.buyPrice  = (decimal)buyPrice / 1000000000000000000;
                    await CheckBDokenBalance();

                    return(View("Index", result));
                }
                catch
                {
                    return(Redirect("~/Login/Index"));
                }
            }
            else
            {
                int      sid    = (int)Session["userID"];
                CertUser result = (from r in db.CertUsers
                                   where r.certUserID == sid
                                   select r).SingleOrDefault();
                result.bdokenPass = "";
                result.sellAmount = 0;
                result.buyAmount  = 0;
                preventResend     = 0;
                BigInteger sellPrice = await BDC.GetSellPrice(result.beternumAddress);

                BigInteger buyPrice = await BDC.GetBuyPrice(result.beternumAddress);

                result.sellPrice = 1 / (decimal)sellPrice;
                result.buyPrice  = (decimal)buyPrice / 1000000000000000000;
                await CheckBDokenBalance();

                return(View("Index", result));
            }
        }