Пример #1
0
        public ActionResult Login(LoginVM data)
        {
            //Eğer kullanıcı zaten giriş yaptıysa, direk üye sayfasına yünlendir vb yapıları kullanabilirsiniz.

            //LoginVM içerisinde yazılan required benzeri kuralları kontrol etme işlemi.
            if (ModelState.IsValid)
            {
                //username ve passswordu eşleşen kişiyi buluyoruz.
                AppUser currentUser = _appUserService.GetByDefault(user => user.UserName == data.UserName && user.Password == data.Password);

                //Bu kişinin bulunup bulunmadığına bakıyoruz.
                if (currentUser != null)
                {
                    //Forms Authentication için Web.Config dosyasına bakmayı unutmayınız
                    //Bu kişi için bir session yani seans oluşturuyoruz.
                    //True yapılırsa, cookie olarak açılır ve tarayıcı kapansa da saklanmaya devam eder, false yapılırsa session yani seans olarak açılır ve tarayıcı kapatıldığında kullanıcı bilgileri kaybolur.
                    //Session ve cookie arasındaki farka bakınız.

                    FormsAuthentication.SetAuthCookie(currentUser.UserName, true);

                    //Eğer rolü admin ise admin area içerisine yönlendiriyoruz.
                    if (currentUser.Role == Role.Admin)
                    {
                        return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                    }

                    //Eğer admin değilse, geldiği sayfaya döner.
                    return(Redirect(Request.UrlReferrer.ToString()));
                }
            }

            //İstersek, yeni kullanıcı sayfasına da yönlendirebiliriz.
            return(RedirectToAction("Signup"));
        }
Пример #2
0
        public ActionResult Login()
        {
            if (User.Identity.IsAuthenticated)
            {
                AppUser currentUser = _appUserService.GetByDefault(x => x.UserName == HttpContext.User.Identity.Name);

                if (currentUser.Role == UserRole.Admin)
                {
                    return(RedirectToAction("Index", "Home", new { area = "admin" }));
                }
                else if (currentUser.Role == UserRole.Member)
                {
                    return(RedirectToAction("Index", "Home", new { area = "member" }));
                }
                else if (currentUser.Role == UserRole.Banned)
                {
                    //Size kalmış
                    return(RedirectToAction(""));
                }
                else
                {
                    //Eğer böyle bir kullanıcı yoksa kayıt sayfasına yönlendir.
                    return(RedirectToAction("Register"));
                }
            }
            return(View());
        }
Пример #3
0
 public ActionResult Index(Tweet tweet)
 {
     tweet.AppUserID   = appUserService.GetByDefault(x => x.UserName == User.Identity.Name).ID;
     tweet.CreatedDate = DateTime.Now;
     tweetService.Add(tweet);
     return(Redirect("/Member/Home/Index"));
 }
Пример #4
0
        public ActionResult Inbox()
        {
            ChatVM model = new ChatVM()
            {
                AppUsers = appUserService.GetActive(),
                Chats    = chatService.GetActive(),
                user     = appUserService.GetByDefault(x => x.UserName == User.Identity.Name)
            };

            return(View(model));
        }
Пример #5
0
        // GET: Member/Home
        public ActionResult Index()
        {
            TweetVM model = new TweetVM()
            {
                AppUsers = appUserService.GetActive(),
                Tweets   = tweetService.GetActive().OrderByDescending(x => x.CreatedDate).ToList(),
                Comments = commentService.GetActive(),
                userName = appUserService.GetByDefault(x => x.UserName == User.Identity.Name).UserName,
                UserID   = appUserService.GetByDefault(x => x.UserName == User.Identity.Name).ID,
            };

            return(View(model));
        }
Пример #6
0
        public ActionResult AddTweet(Tweet data, HttpPostedFileBase Image)
        {
            List <string> UploadedImagePaths = new List <string>();

            UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1);

            data.ImagePath = UploadedImagePaths[0];

            if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2")
            {
                data.ImagePath = ImageUploader.DefaultProfileImagePath;
                data.ImagePath = ImageUploader.DefaultXSmallProfileImage;
                data.ImagePath = ImageUploader.DefaulCruptedProfileImage;
            }
            else
            {
                data.ImagePath = UploadedImagePaths[1];
                data.ImagePath = UploadedImagePaths[2];
            }

            AppUser user = _appUserService.GetByDefault(x => x.UserName == User.Identity.Name);

            data.AppUserID   = user.ID;
            data.CreatedDate = DateTime.Now;

            _tweetService.Add(data);
            return(Redirect("/Member/Home/Index"));
        }
Пример #7
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            //Forms authentication içerisinden gelen userNamei yakaladık.
            string userName = HttpContext.Current.User.Identity.Name;

            //Boş olmadığından emin olduk
            if (!string.IsNullOrWhiteSpace(userName))
            {
                //Kullanıcımızı yakaladık.
                AppUser currentUser = _appUserService.GetByDefault(x => x.UserName == userName);
                //Parametrede belirtilen rolelrden birine kullanıcının rolü uyuyorsa, true, yoksa false dönüyoruz. Bu sayede true dönmezsek, kullanıcı o sayfayı görüntüleyemiyor.
                foreach (var item in _roles)
                {
                    if (currentUser.Role == item)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                //İstersek Error Controller Açar, ve unauthorized sayfasını hazırlarız.
                HttpContext.Current.Response.Redirect("~/Error/Unauthorized");
                return(false);
            }
        }
Пример #8
0
        public ActionResult OrderCreate(Product data)//Kasa Satış ve Mobil satış için sipariş oluşturma sayfası
        {
            //Sepet boşsa ana sayfaya yönlendir.
            if (Session["sepet"] == null)
            {
                return(RedirectToAction("Index", "Cart", new { area = "Member" }));
            }
            //Sepeti yakalıyoruz.
            ProductCart cart = Session["sepet"] as ProductCart;

            //Yeni sipariş oluşturuyoruz.
            Order order = new Order();

            //Siparişin sahibi olan kullanıcının idsini yakaladık.
            order.AppUserID = _appUserService.GetByDefault(x => x.UserName == HttpContext.User.Identity.Name).ID;

            //Sepettki tüm ürünlerde geziyoruz, her ürün için bir sipariş detay oluşturuyoruz(Northwind örneğindeki gibi) ve bu her sipariş detayını siparişe ekliyoruz.
            foreach (var item in cart.CartProductList)
            {
                order.OrderDetails.Add(new OrderDetail
                {
                    ProductID = item.ID,
                    Quantity  = item.Quantity,
                });
            }
            //Deponun onaylayabilmesi için false yapıyoruz.
            order.IsConfirmed = false;

            _orderService.Add(order);

            return(RedirectToAction("OrderList", "Order", new { area = "Member" }));
        }
        public ActionResult Login(AppUser item)
        {
            ViewData["product"]       = ps.GetAll();
            ViewData["category"]      = cs.GetAll();
            ViewData["subcategory"]   = ss.GetAll();
            ViewData["thirdcategory"] = ts.GetAll();
            ViewBag.ProductImage      = imgs.GetAll();
            if (aus.Any(m => m.UserName == item.UserName && m.Password == item.Password))
            {
                AppUser gelen = aus.GetByDefault(m => m.UserName == item.UserName);
                ViewBag.Username = gelen.Name;
                if (gelen.IsPageAdmin == true || gelen.IsAdministrator == true)
                {
                    Session["admin"] = gelen;
                    Session.Timeout  = 10;


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

                Session["oturum"] = gelen;
                Session.Timeout   = 10;


                return(RedirectToAction("Index", "MyPage"));
            }
            else
            {
                ViewBag.Message = "Lütfen girmiş olduğunuz bilgileri kontrol ediniz";
            }
            return(View());
        }
Пример #10
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            //Forms authentication anında olutuştuurlan seansta kulannıcının usernameini saklamıştık. Bunun kontorlü için account controller içerisine bakabilirsiniz. FormsAuth ile kullanıcı giriş yaptığında httpcontext sınıfından o kullanıcı ile ilgili saklanan bilgiye erişebiliriz.

            string userName = HttpContext.Current.User.Identity.Name;

            //Kullanıcının adının boş gelmediğinden emin oluyoruz.

            if (!string.IsNullOrWhiteSpace(userName))
            {
                //Kullanıcının username sütunu eşsiz olmalıdır. Yoksa email gibi bir sütunu tutabilirsiniz.

                //Kullanıcı adı eşleşen user nesnes, yakalanır.
                AppUser currentUser = _appUserService.GetByDefault(user => user.UserName == userName);

                foreach (Role nextRole in _roles)
                {
                    if (currentUser.Role == nextRole)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            //İstersek, Error controller açar ve unauthorized sayfasını hazırlarız.
            HttpContext.Current.Response.Redirect("~/Error/Unauthorized");
            return(false);
        }
        public ActionResult Register()
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                AppUser user = _appUserService.GetByDefault(x => x.UserName == HttpContext.User.Identity.Name);

                if (user.Role == Role.Admin)
                {
                    return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                }
                else if (user.Role == Role.Member)
                {
                    return(RedirectToAction("Index", "Home", new { area = "Member" }));
                }
            }
            return(View());
        }
Пример #12
0
 public ActionResult Aktivasyon(Guid id)
 {
     if (appUser.Any(x => x.ActivationCode == id))
     {
         AppUser aktiveEdilecek = appUser.GetByDefault(x => x.ActivationCode == id);
         aktiveEdilecek.isActive = true;
         appUser.Update(aktiveEdilecek);
     }
     return View();
 }
Пример #13
0
        public ActionResult ArticleAdd(Article article, HttpPostedFileBase Image)
        {
            List <string> UploadedImagePaths = new List <string>();

            UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalImageProfilePath, Image, 1);
            article.ImagePath  = UploadedImagePaths[0];
            if (article.ImagePath == "0" || article.ImagePath == "1" || article.ImagePath == "2")
            {
                article.ImagePath = ImageUploader.DefaultProfileImagePath;
                article.ImagePath = ImageUploader.DefaultXSmallProfileImagePath;
                article.ImagePath = ImageUploader.DefaultCruptedImagesProfileImagePath;
            }
            AppUser user = _appUserService.GetByDefault(x => x.UserName == HttpContext.User.Identity.Name);

            article.AppUserID = user.ID;
            _articleService.Add(article);
            TempData["Başarılı"] = "Successful";
            return(Redirect("/Author/Article/ArticleList"));
        }
Пример #14
0
        public ActionResult Login(AppUser model)
        {
            AppUser kullanici = _appuserService.GetByDefault(x => x.UserName == model.UserName && x.Password == model.Password);

            if (kullanici != null)
            {
                FormsAuthentication.SetAuthCookie(kullanici.UserName, true);
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Пример #15
0
        public ActionResult Add()
        {
            if (Session["sepet"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            //Sepeti yakaladık.
            ProductCart cart = Session["sepet"] as ProductCart;

            if (cart.CartProductList.Count <= 0)
            {
                TempData["Message"] = "Sepet Boş Olamaz!";
                return(RedirectToAction("Index", "Cart"));
            }

            //Yeni sipariş oluşturduk.
            Order newOrder = new Order();

            //Siparişi veren kullanıcıyı yakaladık.
            AppUser currentUser = _appUserService.GetByDefault(x => x.UserName == HttpContext.User.Identity.Name);

            //Sipariş ile kullanıcı atamasını yaptık.
            newOrder.AppUserID = currentUser.ID;

            decimal totalPrice = 0;

            //Sepetteki tüm ürünlerde geziyoruz.
            foreach (var item in cart.CartProductList)
            {
                //Sırayla veritabanından ürünleri yakalıyoruz.
                Product nextCartProduct = _productService.GetById(item.ID);

                totalPrice += item.Quantity * Convert.ToDecimal(1 - nextCartProduct.Discount) * item.UnitPrice;

                //Her ürün için yeni bir sipariş detay oluşturuyoruz.
                newOrder.OrderDetails.Add(new OrderDetail
                {
                    ProductID = nextCartProduct.ID,
                    Quantity  = item.Quantity,
                    UnitPrice = item.UnitPrice
                });
            }

            newOrder.OrderStatus = OrderStatus.Ordered;
            newOrder.OrderDate   = DateTime.Now;
            newOrder.TotalPrice  = totalPrice;
            _orderService.Add(newOrder);

            return(RedirectToAction("Index", "Home"));
        }
Пример #16
0
 public ActionResult Complete(Guid id)
 {
     if (appUserService.Any(x => x.ActivationCode == id))
     {
         AppUser user = appUserService.GetByDefault(x => x.ActivationCode == id);
         user.IsActive       = true;
         user.ActivationCode = Guid.NewGuid();
         appUserService.Update(user);
         ViewBag.ActivationStatus = 1;
     }
     else
     {
         ViewBag.ActivationStatus = 0;
     }
     return(View());
 }
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            AppUser currentUser = _appUserService.GetByDefault(x => x.UserName == HttpContext.Current.User.Identity.Name);

            if (currentUser != null)
            {
                foreach (var item in _roles)
                {
                    if (currentUser.Role.ToString().Trim().ToLower() == item.Trim().ToLower())
                    {
                        return(true);
                    }
                }
            }

            HttpContext.Current.Response.Redirect("~/Account/Login");
            return(false);
        }
        public ActionResult MemberHomeIndex()
        {
            TweetDetailVM model = new TweetDetailVM();
            AppUser       user  = _appUserService.GetByDefault(x => x.UserName == User.Identity.Name);

            model.Tweets   = _tweetService.GetActive().OrderByDescending(x => x.CreatedDate).ToList();
            model.Comments = _commentService.GetActive().OrderBy(x => x.CreatedDate).ToList();

            foreach (var item in model.Tweets)
            {
                model.Tweet        = _tweetService.GetByID(item.ID);
                model.AppUser      = _appUserService.GetByID(model.Tweet.AppUser.ID);
                model.Comments     = _commentService.GetDefault(x => x.TweetID == item.ID || x.Status == TwitterProject.Core.Enum.Status.Active);
                model.Likes        = _likeService.GetDefault(x => x.TweetID == item.ID);
                model.CommentCount = _commentService.GetDefault(x => x.TweetID == item.ID).Count();
                model.LikeCount    = _likeService.GetDefault(x => x.TweetID == item.ID).Count();
            }

            return(View(model));
        }
Пример #19
0
 public ActionResult Login(AppUser item)
 {
     if (aus.Any(m => m.Password == item.Password && m.UserName == item.UserName))
     {
         AppUser gelen   = aus.GetByDefault(x => x.UserName == item.UserName);
         bool    adminmi = gelen.IsAdministrator;
         if (adminmi)
         {
             Session["LoginUser"] = gelen;
             return(RedirectToAction("Index", "Restaurant", new { area = "Administrator" }));
         }
         else
         {
             Session["LoginUser"] = gelen;
             ViewBag.UserName     = gelen.UserName;
             return(RedirectToAction("Index", "Home"));
         }
     }
     else
     {
         //Hatali Kullanici Adi ve Şifre
     }
     return(View());
 }
        public ActionResult Show()
        {
            AppUser user = appUserService.GetByDefault(x => x.UserName == User.Identity.Name);

            return(View(user));
        }