public void UpdateInvitationReceived(CompanyRosterInvitation invitation)
        {
            CompanyRosterInvitation findInvitation = context.Invitations.Find(invitation.InvitationID);

            if (findInvitation != null)
            {
                findInvitation.Received = true;
                context.SaveChanges();
            }
        }
Example #2
0
        protected override void OnAuthentication(System.Web.Mvc.Filters.AuthenticationContext filterContext)
        {
            base.OnAuthentication(filterContext);

            //BEW DEBUG Properties.Settings.Default.debugRoute = true: If you want to actually test your encrypted link (including link expiration and whether or not it is Disabled/Received)
            //BEW DEBUG Properties.Settings.Default.ignoreExpirationDisabledReceived = true: If you just want to authorize any debug link (via decryption) AND resuse it, ignoring expiration, disabled, received

            if (Properties.Settings.Default.debugRoute && Session["AlreadyInitializedRoute"] == null)
            {
                Session["AlreadyInitializedRoute"] = true;
                //BEW DEBUG ROUTE - Set the id parameter that would be passed into the route here; i.e., just the encrypted part: "E61C33CF3700A314499952B514627DA5DD4B4D887E968B41BC6CDF66A62FE257BFF2B2299F0BD186317F7930FCFC6944F83A0C4A44390C39ACB78A32E60EDB115AB1D3CEB1E0D6208E152E3CE26DF5700ECB7EF12015159";
#if DEBUG
                //[email protected]
                //RouteData.Values["id"] = "D555440881A9D9391356C826ADF4475913F08BC6CA66C5758AD3B91D43B4C48408FD3C85D2C2DBC121DED5829579B8CBD3D15EA9C537865736833F427647CD85D8392FF8D3DC12C8DDBC1CD7F1D3A6650DD46069097648F42D0B1F5BE894685D573E79E6A932E450F743F2BFA5D09BAD";
                RouteData.Values["id"] = "7705CD8DC4C9709A2A575ED31ECED37EBBFC2FC3A13CB993D135FC7693FB2DC2FF56C008ACF85A1BC674DDBC3BCD368CD99CFE101AAE383AD935B29951199F69791DD89907E46FD9860F41C76AF83BE1D50FABE318258F68C979554888EDEA0E25A595E4C8FEACC7994BF882E3918124";
                //RouteData.Values["id"] = "7A69042157D7F3745F50C61E41CCC7A770D177B10420E3894FFC18B9B453B449E08731615366329FC6C7172DA19660EEAC419649FD3BB84C400B5B9033A9650B0144F61F61B45DB131E721D99F17BC5DC9DEF098EA4432C81B9BEE320C6360892E241173D9314B2166AF058BAE1A1120";
#elif DEBUGMASHTUN
                RouteData.Values["id"] = "219217C2E18AB6FB6EE7043D796F3709EA92D4DFAC89969567D1957BE44A3B017D868EA888A18B22232D4437FEA56296DBA10F2945753D85C83C067F7679E74658EE32DE88F177FEDA144FF5117CD6B538DA2C0905EC889D57C2D669ACE4EE4BA0746246F1C861064B2AEBCCCEA7BA26";
#else
                RouteData.Values["id"] = "CF67D6679D9F22D4389C951A5E19E9BA17C05F0760706FEED87EDF0E2F405D0B5EF386C57D51E2B24F8B2AF05CFA13B3719D7266C09384D7ED99C2B20266A03CA6E7C6E29AF7EC2CB4CD4BC8F98924FB2FADBA57D8F7495BAEC2CFBD829FC953F364CD206B9E0B442619CA4FC09FD2B7";
#endif
            }

            string id = null;
            if (RouteData.Values["id"] != null)
            {
                // When the app is initialized, we only have RouteData
                id = RouteData.Values["id"].ToString();
            }
            else if (Request.QueryString["q"] != null)
            {
                //OMG!!! MicroSUCK won't allow you to pass a route value longer than 260 characters (the old Windows MAX_PATH),
                //so when it is longer, we have to make it an old fashioned query string, which kind of ruins the MVC pattern, which purports to eliminate the need for ugly old query string params.
                id = Request.QueryString["q"].ToString();
            }
            else if (Session["id"] != null)
            {
                // After the RouteData is fully authenticated (below "AUTHORIZE STEP 3") it is stored in Session for continued use
                id = Session["id"].ToString();
            }

            // AUTHORIZE STEP 1: Let BACrypto decrypt the link and tell us if it's in the correct format
            isAuthorized = id != null && crypto.AuthenticateLink(id, out decryptedLink);
            if (isAuthorized)
            {
                if (decryptedLink != null)
                {
                    linkProperties = decryptedLink.Split('|');

                    /* AUTHORIZE STEP 2: Verify that the link is actually in the database.
                     * We need the database version anyway so we can tell if it (1) has already been used by the recipient, or (2) is expired.
                     */
                    Invitation = InvitationRepository.GetInvitation(GetLinkProperty("IMIS_ID"), decryptedLink);
                    if (Properties.Settings.Default.ignoreExpirationDisabledReceived)
                    {
                        //DEBUG Just store the RouteValue in the Session. We don't care if it's expired, received, disabled.
                        if (Session["id"] == null)
                        {
                            Session["id"] = RouteData.Values["id"];
                        }
                        isAuthorized = true;
                        return;
                    }
                    else
                    {
                        //LIVE
                        isAuthorized = Invitation != null && !(Invitation.Received || Invitation.Disabled);
                    }
                }
                else
                {
                    //ViewData["NotAuthorizedReason"] = "DEBUG ONLY - decryptedLink is null"; //BEW DEBUG ONLY
                    isAuthorized = false;
                }

                const string MSG_INVITATION_EXPIRED  = "Your invitation has expired.";
                const string MSG_INVITATION_RECEIVED = "Your invitation has already been received.";

                if (isAuthorized)
                {
                    /* AUTHORIZE STEP 3: Is the link expired? */
                    DateTime sentDateTime = new DateTime();
                    isAuthorized = (DateTime.TryParse(GetLinkProperty("SentDateTime"), out sentDateTime) && DateTime.Now.Subtract(sentDateTime).TotalDays < 3);
                    if (!isAuthorized)
                    {
                        ViewData["NotAuthorizedReason"] = MSG_INVITATION_EXPIRED;
                    }
                    else if (Session["id"] == null)
                    {
                        if (Request.QueryString["q"] != null)
                        {
                            Session["id"] = Request.QueryString["q"];
                        }
                        else
                        {
                            /*** Store the RouteData id in a Session here, after it has been fully authenticated ***/
                            Session["id"] = RouteData.Values["id"];
                        }
                    }
                }
                else if (Invitation != null)
                {
                    /* If there is a matching invitation in the database, then provide details about why it is invalid
                     * If it is disabled, just tell the user it's expired. (Don't want to say "you're uninvited".
                     * Otherwise say it is received. */
                    ViewData["NotAuthorizedReason"] = (Invitation.Disabled) ? MSG_INVITATION_EXPIRED : MSG_INVITATION_RECEIVED;
                }
            }

            if (!isAuthorized)
            {
                filterContext.Result = View("~/Views/Shared/NotAuthorized.cshtml");
            }
        }