protected void Page_Load(object sender, EventArgs e)
    {
        // Extract the forms authentication cookie
        string     cookieName = FormsAuthentication.FormsCookieName;
        HttpCookie authCookie = Context.Request.Cookies[cookieName];

        if (null == authCookie)
        {
            Server.Transfer("Login.aspx", true);
        }

        FormsAuthenticationTicket authTicket = null;

        try
        {
            authTicket = FormsAuthentication.Decrypt(authCookie.Value);
        }
        catch (Exception ex)
        {
            // Log exception details (omitted for simplicity)
            return;
        }

        if (null == authTicket)
        {
            // Cookie failed to decrypt.
            return;
        }

        Debug.WriteLine(authTicket.ToString());
    }
        public ActionResult Index(LoginViewModel logindetails)
        {
            if (ModelState.IsValid)
            {
                if (logindetails != null)
                {
                    if (logindetails.UserName.ToLower() == "vishnu" && logindetails.Password.ToLower() == "vishnu")
                    {
                        FormsAuthenticationTicket formsAuthenticationTicket = new FormsAuthenticationTicket(

                            1, logindetails.UserName, DateTime.Now, new DateTime().AddDays(2), false, "Admin");

                        FormsAuthentication.SetAuthCookie(formsAuthenticationTicket.ToString(), false);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(new HttpUnauthorizedResult("User is UnAuthorized to Access the Site"));
                    }
                }
            }

            ModelState.AddModelError("Validate", "There was some error happend in processing");
            return(View());
        }
Beispiel #3
0
        public bool PostJellyVisionQuizResponse(string id, string referrerID, string responses, string personalityType, string encryptedToken)
        {
            const string logMethodName = ".PostJellyVisionQuizResponse(string id, string referrerID, string responses, string personalityType) - ";

            _log.Debug(logMethodName + "Begin Method");
            _log.Debug(logMethodName + string.Format("id = [{0}], referrerID = [{1}], responses = [{2}], personalityType = [{3}]", id, referrerID, responses, personalityType));

            try
            {
                bool toReturn = false;
                //allow all the origin url to avoid cross domain issue.
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
                }

                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encryptedToken);
                if (string.IsNullOrEmpty(ticket.ToString()))
                {
                    _log.Debug("Something wrong during the decryption process!");
                    return(false);
                }

                //validate the request with the values extracted from the token
                if (!ticket.Expired && ticket.Name == id && ticket.UserData == "1")
                {
                    JellyVisionQuizResponseModel jvqResponse = new JellyVisionQuizResponseModel();

                    //hardcoding the quizName for now. If we get another then we'll have to change this.
                    jvqResponse.quizName = "Money Personality Quiz";

                    jvqResponse.Id              = !string.IsNullOrWhiteSpace(id) ? int.Parse(id) : 0;
                    jvqResponse.referrerID      = referrerID;
                    jvqResponse.responses       = responses;
                    jvqResponse.personalityType = personalityType;

                    if (JellyVisionQuizResponseValidation.validateQuizResponseModel(jvqResponse))
                    {
                        toReturn = _surveyAdapter.AddJellyVisionQuizResponse(jvqResponse);
                    }
                }
                else
                {
                    _log.Debug(logMethodName + "the request expired.");
                }

                _log.Debug(logMethodName + "End Method");

                return(toReturn);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + ": Exception => " + ex.ToString());
                return(false);
                //throw new SurveyOperationException("Web Survey Service - Exception in ASA.Web.Services.SurveyService.PostJellyVisionQuizResponse()", ex);
            }
        }
Beispiel #4
0
        public ActionResult Login(User reg)
        {
            if (ModelState.IsValid)
            {
                var details = (from userlist in db.Users
                               where userlist.users_number == reg.users_number && userlist.users_password == reg.users_password
                               select new
                {
                    userlist.users_id,
                    userlist.users_number,
                    userlist.users_name,
                    userlist.users_country_id,
                    userlist.users_credits,
                    userlist.users_diseases,
                    userlist.users_dob,
                    userlist.users_email,
                    userlist.users_mobility,
                    userlist.users_password
                }).ToList();
                if (details.FirstOrDefault() != null)
                {
                    Session["users_id"]         = details.FirstOrDefault().users_id;
                    Session["users_number"]     = details.FirstOrDefault().users_number;
                    Session["users_name"]       = details.FirstOrDefault().users_name;
                    Session["users_country_id"] = details.FirstOrDefault().users_country_id;
                    Session["users_credits"]    = details.FirstOrDefault().users_credits;
                    Session["users_diseases"]   = details.FirstOrDefault().users_diseases;
                    Session["users_dob"]        = details.FirstOrDefault().users_dob;
                    Session["users_email"]      = details.FirstOrDefault().users_email;
                    Session["users_mobility"]   = details.FirstOrDefault().users_mobility;
                    Session["users_password"]   = details.FirstOrDefault().users_password;


                    FormsAuthentication.SetAuthCookie(Session["users_number"].ToString(), false);

                    var authTicket = new FormsAuthenticationTicket(1, Session["users_number"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(20), false, Session["users_id"].ToString());
                    //   string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    // var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, authTicket.ToString());
                    HttpContext.Response.Cookies.Add(authCookie);

                    return(RedirectToAction("Welcome", "Home"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Invalid Credentials");
            }
            return(View(reg));
        }