예제 #1
0
        public ActionResult Login(AdminLoginViewModel model, string returnUrl)
        {
            var admin = accountService.AdminLogin(model.Account, model.Password);

            if (admin != null)
            {
                LocalDateTimeService timeService = new LocalDateTimeService();
                var today = timeService.GetLocalDateTime(LocalDateTimeService.CHINA_STANDARD_TIME);
                var name  = admin.Adm_Name;
                HttpContext.Session.Clear();
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                                                                                 name,
                                                                                 today,
                                                                                 DateTime.Now.AddHours(24),
                                                                                 false,
                                                                                 "Admin"
                                                                                 );

                string enTicket = FormsAuthentication.Encrypt(ticket);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, enTicket));
                return(Redirect("/Admin/Soap"));
            }

            TempData["loginFail"] = "帳號或密碼錯誤!";
            return(View());
        }
예제 #2
0
        public IHttpActionResult Create(CreateNewsDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var instance = Mapper.Map <CreateNewsDTO, News>(dto);

            instance.AddTime = timeService.GetLocalDateTime(LocalDateTimeService.CHINA_STANDARD_TIME);
            var result = newsService.CreateNews(instance);

            if (!result.Success)
            {
                return(BadRequest(result.Message.ToString()));
            }
            return(Created(new Uri(Request.RequestUri + "/" + instance.Id), instance));
        }
예제 #3
0
        public ActionResult Login(LoginViewModel vm)
        {
            var customer = accountService.Login(vm);

            if (customer != null)
            {
                LocalDateTimeService timeService = new LocalDateTimeService();
                var today = timeService.GetLocalDateTime(LocalDateTimeService.CHINA_STANDARD_TIME);
                var name  = customer.Name;
                HttpContext.Session.Clear();
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                                                                                 name,
                                                                                 today,
                                                                                 DateTime.Now.AddHours(24),
                                                                                 false,
                                                                                 "User"
                                                                                 );

                var idCookie = new HttpCookie("IdCookie");
                idCookie.Expires.AddHours(24);
                idCookie.Values.Add("customer_id", customer.Id);
                //Encrypt cookie
                string enTicket = FormsAuthentication.Encrypt(ticket);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, enTicket));
                Response.Cookies.Add(idCookie);

                //string decodedUrl = "";
                //if (!string.IsNullOrEmpty(returnUrl))
                //    decodedUrl = Server.UrlDecode(returnUrl);

                ////Login logic...

                //if (Url.IsLocalUrl(decodedUrl))
                //{
                //    return Redirect(decodedUrl);
                //}

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

            ModelState.AddModelError("Password", "帳號或密碼錯誤,請重新確認");
            return(View(vm));
        }