Beispiel #1
0
        public IActionResult Signup(User u, string password)
        {
            var db = new AdsDB(_connectionString);

            db.AddUser(u, password);
            return(Redirect("/Account/Login"));
        }
Beispiel #2
0
        public IActionResult Delete(int adId)
        {
            var db = new AdsDB(_connectionString);

            db.DeleteAd(adId);
            return(Redirect("/"));
        }
Beispiel #3
0
        public IActionResult MyAcount()
        {
            var db        = new AdsDB(_connectionString);
            int currentId = db.GetByEmail(User.Identity.Name).Id;

            return(Redirect($"/Home/index?id={currentId}"));
        }
Beispiel #4
0
        public IActionResult NewAd(Ad a)
        {
            var  db = new AdsDB(_connectionString);
            User u  = db.GetByEmail(User.Identity.Name);

            db.AddAd(a, u);
            return(Redirect("/"));
        }
Beispiel #5
0
        public IActionResult Index(int id)
        {
            var db = new AdsDB(_connectionString);
            var vm = new HomePageViewModel()
            {
                Ads = db.GetAds(id)
            };

            if (User.Identity.IsAuthenticated)
            {
                vm.UserId = db.GetByEmail(User.Identity.Name).Id;
            }
            return(View(vm));
        }
Beispiel #6
0
        public IActionResult Login(string email, string password)
        {
            var  db = new AdsDB(_connectionString);
            User u  = db.Login(email, password);

            if (u == null)
            {
                TempData["message"] = "Invalid password/email combination. Try again";
                return(Redirect("/Account/Login"));
            }
            var claims = new List <Claim>
            {
                new Claim("user", email)
            };

            HttpContext.SignInAsync(new ClaimsPrincipal(
                                        new ClaimsIdentity("claims", "cookies", "role"))).Wait();
            return(Redirect("/"));
        }