Example #1
0
        public HttpResponseMessage ValidateTracerGuestUserByEmail(string email, int siteID = 0)
        {
            ApiMobileValidateGuestUserReturnModel rtn = new ApiMobileValidateGuestUserReturnModel();

            try
            {
                string errMsg = string.Empty;

                rtn = guestUserService.ValidateGuestUser(email, siteID, out errMsg);


                if (string.IsNullOrEmpty(errMsg))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, rtn));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errMsg));
                }
            }
            catch (Exception ex)
            {
                WebExceptionHelper.LogException(ex, null);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "There was an error validating the user. Please contact your Program Administrator."));
            }
        }
Example #2
0
        public ApiMobileValidateGuestUserReturnModel ValidateGuestUser(string userLogin, int siteID, out string errMessage)
        {
            ApiMobileValidateGuestUserReturnModel rtn = new ApiMobileValidateGuestUserReturnModel();

            using (var db = new DBMEdition01Context())
            {
                try
                {
                    errMessage = string.Empty;

                    var rtnList = db.ApiMobileValidateGuestUser(userLogin, siteID);
                    if (rtnList != null && rtnList.Count > 0)
                    {
                        rtn = rtnList.FirstOrDefault();
                    }


                    if ((bool)rtn.IsNewUser)
                    {
                        if (siteID == 0)
                        {
                            errMessage = "No valid guest links available. Please contact your Program Administrator.";
                        }
                        else
                        {
                            MailAddress address     = new MailAddress(userLogin);
                            string      currentHost = "@" + address.Host;

                            var isInvalidDomain = GetGuestAccessDomains(siteID, currentHost);
                            if (isInvalidDomain)
                            {
                                errMessage = "You do not have access to this guest tracer. Please contact your Program Administrator.";
                            }
                        }
                    }
                    else
                    {
                        if (siteID > 0)
                        {
                            MailAddress address     = new MailAddress(userLogin);
                            string      currentHost = "@" + address.Host;

                            var isInvalidDomain = GetGuestAccessDomains(siteID, currentHost);
                            if (isInvalidDomain)
                            {
                                errMessage = "You do not have access to this guest tracer. Please contact your Program Administrator.";
                            }
                        }
                        else
                        {
                            var sites = this.GetGuestUserSites((int)rtn.UserID, userLogin);
                            if (sites.Count > 0)
                            {
                                return(rtn);
                            }
                            else
                            {
                                errMessage = "No valid guest links available. Please contact your Program Administrator.";
                                return(rtn);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string sqlParam   = "ApiMobileValidateGuestUser(" + userLogin + ")";
                    string methodName = "JCRAPI/Business/GuestUserServices/ValidateTracerGuestUser";
                    exceptionLog.ExceptionLogInsert(ex.Message.ToString(), "", methodName, null, null, sqlParam, string.Empty);
                    errMessage = "There was an error validating the user. Please contact your Program Administrator.";
                    return(null);
                }
            }
            return(rtn);
        }