Ejemplo n.º 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            ViewBag.SiteName = _repoSet[SettingKey.SiteName];
            if (ModelState.IsValid)
            {
                FrmBlog.Models.User user = _repoUser.GetUserByEmail(model.UserName, model.Password);
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Email veya şifre yanlış.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        //protected override bool AuthorizeCore(HttpContextBase httpContext)
        //{

        //    if (httpContext.Request.IsAuthenticated)
        //    {
        //        return true;
        //    }
        //    return false;
        //}
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            var context = filterContext.HttpContext;

            if (context.User != null && context.User.Identity.IsAuthenticated)
            {
                var email = context.User.Identity.Name;
                var user  = userRepo.GetUserByEmail(email);


                if (user == null)
                {
                    formsAuth.SignOut();
                }
                else
                {
                    GenericPrincipal gen = new GenericPrincipal(user.Identity, null);
                    AuthenticateAs(context, user);

                    return;
                }
            }

            //AuthenticateAs(context, User.Guest);
        }
Ejemplo n.º 3
0
        public ActionResult Detay(long id, string title)
        {
            FrmViewData frm = new FrmViewData();

            frm.Question = _repoQues.GetById(id);
            if (frm.Question.State == State.Yayinda)
            {
                frm.Tags    = _repoTag.GetListByQuestionId(id);
                frm.Answers = _repoAns.GetListByQuestionId(id);
                List <Question> benzerSorular = BulBenzerSorulari <long>(frm);
                frm.Questions = benzerSorular;
                User user = null;

                if (Request.IsAuthenticated)
                {
                    user = _repoUser.GetUserByEmail(HttpContext.User.Identity.Name);
                }
                long userId = 0;
                if (user == null)
                {
                    userId = 0;
                }
                else
                {
                    userId = user.UserId;
                }
                if (frm.Question.Title.ConvertWebUrl() == title)
                {
                    InsertPageIstatik(userId, id);
                }

                ViewBag.Title = frm.Question.Title;
                return(View(frm));
            }
            else
            {
                TempData["mesaj"] = "Soru yayından kaldırılmış";
                return(RedirectToAction("Succeed", "Soru"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult LogOnPostAssertion(string openid_openidAuthData)
        {
            IAuthenticationResponse response;

            if (!string.IsNullOrEmpty(openid_openidAuthData))
            {
                var auth    = new Uri(openid_openidAuthData);
                var headers = new WebHeaderCollection();
                foreach (string header in Request.Headers)
                {
                    headers[header] = Request.Headers[header];
                }

                // Always say it's a GET since the payload is all in the URL, even the large ones.
                HttpRequestInfo clientResponseInfo = new HttpRequestInfo("GET", auth, auth.PathAndQuery, headers, null);
                response = RelyingParty.GetResponse(clientResponseInfo);
            }
            else
            {
                response = RelyingParty.GetResponse();
            }
            if (response != null)
            {
                switch (response.Status)
                {
                case AuthenticationStatus.Authenticated:
                    string alias = response.FriendlyIdentifierForDisplay;
                    var    sreg  = response.GetExtension <ClaimsResponse>();
                    if (sreg != null && sreg.MailAddress != null)
                    {
                        RepositoryUser userRepo = new RepositoryUser("", DbType.SqLite);
                        if (!userRepo.IsRecordUser(sreg.MailAddress.Address.Trim()))
                        {
                            FrmBlog.Models.User user = new FrmBlog.Models.User();
                            user.DisplayName = sreg.MailAddress.DisplayName;
                            user.Email       = sreg.MailAddress.Address;
                            user.RecordDate  = DateTime.Now;
                            user.RoleId      = FrmBlog.Models.Role.Member.RoleId;
                            user.Name        = sreg.MailAddress.User;
                            user.PicturePath = new FrmBlog.Avatar.Avatar().GetRandomAvatar();
                            userRepo.Insert(user);
                        }
                        else
                        {
                            var user = userRepo.GetUserByEmail(sreg.MailAddress.Address);
                        }
                        //FormsAuthenticationTicket authTicket = new
                        //FormsAuthenticationTicket(1, //version
                        //response.ClaimedIdentifier, // user name
                        //DateTime.Now,             //creation
                        //DateTime.Now.AddMonths(12), //Expiration
                        //true, //Persistent
                        //sreg.MailAddress.Address);

                        //  string encTicket = FormsAuthentication.Encrypt(authTicket);

                        //  this.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                        //  alias = sreg.MailAddress.User;
                        FormsAuthentication.SetAuthCookie(sreg.MailAddress.Address, true);
                    }
                    //if (sreg != null && !string.IsNullOrEmpty(sreg.FullName))
                    //{
                    //    alias = sreg.FullName;
                    //}

                    //FormsAuthenticationTicket authTicket = new
                    //    FormsAuthenticationTicket(1, //version
                    //    response.ClaimedIdentifier, // user name
                    //    DateTime.Now,             //creation
                    //    DateTime.Now.AddDays(365), //Expiration
                    //    false, //Persistent
                    //    alias);

                    //string encTicket = FormsAuthentication.Encrypt(authTicket);

                    //this.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));


                    string returnUrl = Request.Form["returnUrl"];
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                case AuthenticationStatus.Canceled:
                    ModelState.AddModelError("OpenID", "It looks like you canceled login at your OpenID Provider.");
                    break;

                case AuthenticationStatus.Failed:
                    ModelState.AddModelError("OpenID", response.Exception.Message);
                    break;
                }
            }

            // If we're to this point, login didn't complete successfully.
            // Show the LogOn view again to show the user any errors and
            // give another chance to complete login.
            return(View("LogOn"));
        }