Example #1
0
        public ActionResult Login(FormLoginUser luser)
        {
            User user = Models.User.getByEmail(luser.email);

            if (user == null)
            {
                ViewBag.Message = "Email does not exist";
            }
            else
            {
                if (!user.ValidatePassword(luser.password))
                {
                    ViewBag.Message = "Bad password";
                }
                else
                {
                    if (user.admin_flag)
                    {
                        Session[KeysUtils.SessionAdmin()] = user;
                        return(RedirectToAction("Index", "Admin"));
                    }
                    else
                    {
                        Session[KeysUtils.SessionUser()] = user;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            return(View(luser));
        }
        public ActionResult CreateAuction(FormCreateAuction fcAuction)
        {
            User u = (User)Session[KeysUtils.SessionUser()];

            if (u == null)
            {
                u = (User)Session[KeysUtils.SessionAdmin()];
                if (u == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            if (ModelState.IsValid)
            {
                Auction a = Auction.Create(fcAuction, u.user_id);
                a.save();
                ViewBag.Status  = true;
                ViewBag.Message = "Successfuly creaed auction";
            }
            else
            {
                ViewBag.Message = "Invalid request";
            }

            return(View(fcAuction));
        }
Example #3
0
        public ActionResult ChangeProfile(FormChangeUser u)
        {
            User user = (User)Session[KeysUtils.SessionUser()];

            if (!user.email.Trim().Equals(u.email) && Models.User.EmailExists(u.email))
            {
                ModelState.AddModelError("EmailExists", "Email already exists");
            }
            else
            {
                if (u.password == null || u.password.Trim().Equals(""))
                {
                    u.password = ((User)(Session[KeysUtils.SessionUser()])).password;
                }
                else
                {
                    user.password = CryptUtils.Hash(u.password);
                }
                user.email      = u.email;
                user.first_name = u.firstName;
                user.last_name  = u.lastName;
                user.saveChanges();
                Session[KeysUtils.SessionUser()] = user;
                ViewBag.Status  = true;
                ViewBag.Message = "Changed profile  successfully";
            }



            return(View(u));
        }
Example #4
0
        public ActionResult InsertBid(Guid auction_id, int token_price)
        {
            User user = (User)Session[KeysUtils.SessionUser()];

            if (user != null)
            {
                Bid bid = Bid.factoryMethod(user.user_id, auction_id, token_price + 1);
                bid.processBid();
            }
            return(RedirectToAction("Index", "Home"));
        }
Example #5
0
        public ActionResult MyOrders()
        {
            User u = (User)Session[KeysUtils.SessionUser()];

            if (u == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                List <TokenOrder> to = TokenOrder.getOrdersForUser(u.user_id);
                return(View(to));
            }
        }
Example #6
0
        public ActionResult MyTokens()
        {
            User u = (User)Session[KeysUtils.SessionUser()];

            if (u == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                u = Models.User.getById(u.user_id);
                ViewBag.tokens = u.tokens;
                return(View());
            }
        }
Example #7
0
        public ActionResult MyWinns()
        {
            User u = (User)Session[KeysUtils.SessionUser()];

            if (u == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                List <Bid>     ll = Bid.WonBids(u.user_id);
                List <Auction> la = new List <Auction>();
                foreach (Bid b in ll)
                {
                    la.Add(Auction.getByKey(b.auction_id));
                }
                return(View(la));
            }
        }
Example #8
0
        public ActionResult ChangeProfile()
        {
            User u = (User)Session[KeysUtils.SessionUser()];

            if (u == null)
            {
                return(RedirectToAction("Register", "Home"));
            }
            else
            {
                FormChangeUser fcu = new FormChangeUser();
                fcu.lastName  = u.last_name.Trim();
                fcu.firstName = u.first_name.Trim();
                fcu.email     = u.email;
                fcu.password  = "";

                return(View(fcu));
            }
        }
Example #9
0
 public ActionResult SignOut()
 {
     Session[KeysUtils.SessionUser()]  = null;
     Session[KeysUtils.SessionAdmin()] = null;
     return(RedirectToAction("Index", "Home"));
 }