Example #1
0
        public ActionResult ChangePassword(ChangePasswordViewModel changePassView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    User user = db.FindUser(logged_user.email);

                    if (user.password != EncodePassword(changePassView.ConfirmPassword))
                    {
                        throw new Exception("Wrong password.");
                    }

                    user.password = EncodePassword(changePassView.NewPassword);
                    db.SaveChanges();
                }
            }
            catch (Exception error)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message));
            }
            return(null);
        }
Example #2
0
        public ActionResult ChangeName(ChangeNameViewModel changeNameView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    User user = db.FindUser(logged_user.email);

                    user.first_name = changeNameView.New_first_name;
                    user.last_name  = changeNameView.New_last_name;

                    db.SaveChanges();
                }
            }
            catch (Exception error)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("AccountDetails"));
        }
Example #3
0
        public ActionResult Login(LoginViewModel loginView)
        {
            try {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    User user = db.FindUser(loginView.Email);
                    if (user == null)
                    {
                        throw new Exception("There is no user with that e-mail.");
                    }

                    if (user.password != EncodePassword(loginView.Password))
                    {
                        throw new Exception("Wrong password.");
                    }

                    Session["user"] = new PartialUser(user);
                }
            }
            catch (Exception error)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message));
            }
            return(PartialView("_Header"));
        }
Example #4
0
        public ActionResult Bid(BidViewModel bidView) //////////PROVERI DA LI IMAS DOVOLJNO PARA
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    Guid auction_id = new Guid(bidView.Auction_id);

                    if (logged_user.email == db.GetAuction(auction_id).owner)
                    {
                        throw new Exception("You can not bid your own auction!");
                    }

                    Bid last_bid = db.GetLastBid(auction_id);
                    if (bidView.Amount <= (last_bid != null ? last_bid.amount : db.GetAuction(auction_id).starting_price))
                    {
                        throw new Exception("Your bidding amount must be greater then the last one!");
                    }

                    if (db.GetAvailableTokens(logged_user.email) < bidView.Amount)
                    {
                        throw new Exception("You have not enough tokens to procceed with the transaction!");
                    }

                    Bid bid = new Bid
                    {
                        id         = Guid.NewGuid(),
                        auction_id = auction_id,
                        bidder     = logged_user.email,
                        created    = DateTime.Now,
                        amount     = bidView.Amount
                    };
                    db.Bids.Add(bid);
                    db.SaveChanges();

                    string name = logged_user.first_name + " " + logged_user.last_name;
                    AuctionHouseHub.HubContext.Clients.All.updatebid(logged_user.email, name, bidView.Auction_id, bidView.Amount, bid.created.ToString());
                }
            }
            catch (Exception error)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message));
            }
            return(null);
        }
Example #5
0
        public ActionResult CreateAuction(CreateAuctionViewModel auctionView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                if (auctionView.Image == null)
                {
                    throw new Exception("File was not uploaded");
                }

                var postedFileExtension = Path.GetExtension(auctionView.Image.FileName);
                if (!string.Equals(postedFileExtension, ".png", StringComparison.OrdinalIgnoreCase))
                {
                    throw new Exception("Wrong image type: .png is required type!");
                }

                Guid guid = Guid.NewGuid();
                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    Auction auction = new Auction
                    {
                        id             = guid,
                        name           = auctionView.Name,
                        description    = auctionView.Description,
                        starting_price = auctionView.Starting_price,
                        duration       = auctionView.Days * 60 * 60 * 24 + auctionView.HH * 60 * 60 + auctionView.MM * 60 + auctionView.SS,
                        created        = DateTime.Now,
                        owner          = logged_user.email,
                        state          = "READY"
                    };
                    db.Auctions.Add(auction);
                    db.SaveChanges();
                }

                string path = Path.Combine(Server.MapPath("~/Images"), guid.ToString() + ".png");
                auctionView.Image.SaveAs(path);
                // OBAVESTI SVE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            }
            catch (Exception error)
            {
                TempData["error"] = error.Message;
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Example #6
0
        public PartialUser IsAdmin()
        {
            PartialUser user = IsLoggedIn();

            if (user == null ||
                user.is_administrator == 0)
            {
                return(null);
            }
            return(user);
        }
Example #7
0
        public ActionResult OrderTokens(OrderTokensViewModel orderView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    SystemParameter sp    = db.GetSystemParameters();
                    TokenOrder      order = new TokenOrder
                    {
                        id      = Guid.NewGuid(),
                        orderer = logged_user.email,
                        amount  = (int)orderView.Package,
                        price   = (int)orderView.Package * sp.T,
                        state   = "SUBMITTED"
                    };

                    db.TokenOrders.Add(order);
                    db.SaveChanges();

                    HttpStatusCodeResult service_result = TokenWebService(order.id);
                    if (service_result.StatusCode != 0xca)
                    {
                        throw new Exception(service_result.ToString());
                    }

                    User user = db.FindUser(logged_user.email);
                    user.tokens_amount += order.amount;
                    db.SaveChanges();
                }
            }
            catch (Exception error)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message));
            }
            return(null);
        }
        public IActionResult Get()
        {
            try
            {
                WebClient client = new WebClient();

                client.Headers.Add("Authorization", $"Bearer {Request.Headers["Authorization"]}");
                string userData = client.DownloadString("https://discordapp.com/api/v6/users/@me");

                PartialUser pUser = JsonConvert.DeserializeObject <PartialUser>(userData);

                return(new OkObjectResult(pUser));
            }
            catch
            {
                return(new BadRequestResult());
            }
        }
Example #9
0
        public static Permissions.PermissionLevels GetPermissions(string Token, ulong GuildId)
        {
            if (string.IsNullOrEmpty(Token))
            {
                return(Permissions.PermissionLevels.None);
            }

            try
            {
                WebClient client = new WebClient();
                client.Headers.Add("Authorization", $"Bearer {Token}");
                string userData = client.DownloadString("https://discordapp.com/api/v6/users/@me");

                PartialUser pUser = JsonConvert.DeserializeObject <PartialUser>(userData);
                return(Permissions.GetPermissions(pUser.id, GuildId));
            }
            catch
            {
                return(Permissions.PermissionLevels.None);
            }
        }
Example #10
0
        public async Task <PCISafeCardDetails> CreateSavedCardAsync(MeUserWithXp shopper, PCISafeCardDetails card)
        {
            var customerID = shopper?.xp?.PaymentProcessorCustomerID;
            var customer   = new PaymentSystemCustomer()
            {
                ID                    = shopper?.xp?.PaymentProcessorCustomerID, // cannot assume customer ID is set-able
                Email                 = shopper.Email,
                FirstName             = shopper.FirstName,
                LastName              = shopper.LastName,
                CustomerAlreadyExists = customerID != null,
            };
            var savedCard = await _creditCardSaver.CreateSavedCardAsync(customer, card);

            if (!customer.CustomerAlreadyExists)
            {
                var patch = new PartialUser <MeUserWithXp>()
                {
                    xp = new { PaymentProcessorCustomerID = savedCard.CustomerID }
                };
                await _oc.Users.PatchAsync(shopper.Buyer.ID, shopper.ID, patch);
            }
            return(savedCard.Card);
        }
Example #11
0
        public ActionResult SearchAuctions(SearchAuctionsViewModel auctionView)
        {
            PartialUser logged_user = IsLoggedIn();

            using (AuctionHouseModel db = new AuctionHouseModel())
            {
                string owned = null;
                string won   = null;
                string state = null;
                switch (auctionView.Filter)
                {
                case SearchAuctionsViewModel.FilterEnum.OWNED:
                    if (logged_user != null)
                    {
                        owned = logged_user.email;
                    }
                    break;

                case SearchAuctionsViewModel.FilterEnum.WON:
                    if (logged_user != null)
                    {
                        won = logged_user.email;
                    }
                    break;

                default:
                    state = auctionView.Filter.ToString();
                    break;
                }
                var auctions = db.GetAuctionsWithLastBid(1000, 0,
                                                         auctionView.Regex, state,
                                                         auctionView.Max_price, auctionView.Min_price,
                                                         won, owned);

                return(Json(auctions, JsonRequestBehavior.AllowGet));
            }
        }
Example #12
0
        public ActionResult AccountDetails()
        {
            try
            {
                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    UserDetails             user = db.GetUserDetails(logged_user.email);
                    PartialSystemParameters sp   = db.GetPartialSystemParameters();
                    ViewBag.User         = user;
                    ViewBag.SystemParams = sp;
                    return(View());
                }
            }
            catch (Exception error)
            {
                return(RedirectToAction("Index"));
            }
        }
Example #13
0
 public User (PartialUser p) : base(null, true, true)
 {
     this.CurrentObject = new ExpandoObject();
     this.CurrentObject.BaseId = p.Id;
     this.CurrentObject.DisplayName = p.Name;
     this.IsPartialUser = true;
     this.ReadOnly = true;
 }
 public ChangeNameViewModel(PartialUser user)
 {
     New_first_name = user.first_name;
     New_last_name  = user.last_name;
 }