예제 #1
0
        private void ProcessServiceSignOut()
        {
            string clientId = GetCookieValue("ud");

            this.SiteAppRunner().AppServiceClient.Then((Func <IAppServiceClient, object>)(c =>
            {
                HelixServiceClient helixServiceClient1 = c as HelixServiceClient;
                //VisitUserModel visitUserModel = GenericResultSerializedExtension.ToVisitUserModel(this.GetSessionInforByUserId(sfid));
                //this.log.InfoFormat("accesskey:{0}", (object)TextExtensions.SerializeToString<VisitUserModel>(visitUserModel));
                try
                {
                    clientId = this.GetCookieValue("ud");
                    if (!string.IsNullOrEmpty(clientId) && helixServiceClient1 != null)
                    {   //ServiceTokenModel clientToken = ((VisitorModel)visitUserModel).ClientToken;
                        //string accessToken = clientToken != null ? clientToken.Token : (string)null;
                        helixServiceClient1.SignOff(clientId, null);
                    }
                }
                catch (Exception ex)
                {
                    log.ErrorFormat("signoff exception:{0}, inner:{1}", ex.Message, ex.InnerException?.Message);
                }

                AppSessionServices.DisposeAppCookie(System.Web.HttpContext.Current, "anouser");
                this.ClearCookie("ud");
                return((object)c);
            }));
            //this.ClearCookie("hlsession");
            this.SingOutCleanUp();
            Telerik.Sitefinity.Security.SecurityManager.Logout();
        }
예제 #2
0
        public ActionResult Index(string code = "")
        {
            //return Content(String.Format("access code: {0}", code));
            if (SystemManager.IsDesignMode || SystemManager.IsPreviewMode)
            {
                return(View("Index"));
            }
            this.CreateOrUpdateCookie("cd", code);

            QueryDataResponse <HelixIndividual> qryIndv = new QueryDataResponse <HelixIndividual>()
            {
                ResponseStatus = ResponseStatus.Warning
            };
            //VisitUserModel bfAuth = this.GetSetAppSiteUser();
            VisitUserModel authUser  = new VisitUserModel(); //this.GetSessionInforByUserId(this.MyId()).ToVisitUserModel();
            string         returnUrl = this.GetCookieValue("reqUri");

#if DEBUG
            log.InfoFormat("myId in login:{0}, code:{1}", this.MyId(), code);
#endif

            // if not login & have a code then do authentication
            if ((this.MyId().IsNullOrEmptyGuid() || this.MyId().IsOneGuid()) && !String.IsNullOrEmpty(code))
            {
                this.SiteAppRunner().AppServiceClient
                .Then(cl =>
                {
                    HelixServiceClient client = cl as HelixServiceClient;
                    HelixIndividual helixIndv = new HelixIndividual();

                    client.ActivateHelixbyCode(code);
                    qryIndv = client.DataResponse();
                    if (qryIndv.ResponseStatus.Is(ResponseStatus.Success))
                    {
                        helixIndv = qryIndv.Result;

                        // RWB 20171013 Test
                        this.CreateOrUpdateCookie("IAFC", $"ContactId={helixIndv.MembershipId}&Password=H5erUjDICjI7EM4zJG3%2byg%3d%3d");
                        // RWB 20171013 Test

                        // RWB 20171012 - Username must be an email address for new accounts
                        helixIndv.UserName   = helixIndv.Email;
                        VisitUserModel _vusr = helixIndv;     // derived from the same class base
                        _vusr.ClientId       = helixIndv.Client_id;
                        _vusr.Title          = helixIndv.Title;
                        _vusr.ClientToken    = new ServiceTokenModel()
                        {
                            ClientId      = helixIndv.MembershipId,
                            ClientName    = helixIndv.Email,
                            Token         = helixIndv.access_token,
                            IssueTime     = DateTime.UtcNow,
                            ExpireTime    = DateTime.UtcNow.AddMinutes(12),
                            Refresh_token = helixIndv.Refresh_token,
                            Message       = (new HelixIndividual()
                            {
                                Title = helixIndv.Title, Client_id = helixIndv.Client_id, MembershipId = helixIndv.MembershipId
                            }).SerializeToString()
                                            //Message = (new { Title = helixIndv.Title, MembershipId = helixIndv.MembershipId, Client_id = helixIndv.Client_id }).ToJson()
                        };
                        _vusr.ReturnUrl = returnUrl;
                        _vusr.Profile   = new VisitorProfile()
                        {
                            Roles = new List <UserRole>()
                            {
                                new UserRole()
                                {
                                    Name = "NonMember"
                                }
                            }
                        };

                        /*if (!String.IsNullOrEmpty(helixIndv.MembershipId))
                         * {
                         *  _vusr.Profile.Roles = new List<UserRole>() { new UserRole() { Name = "Member" } };
                         * }*/
                        if (!String.IsNullOrEmpty(helixIndv.roles) && helixIndv.roles.ToLower().IndexOf("iafcmember") >= 0)
                        {
                            _vusr.Profile.Roles = new List <UserRole>()
                            {
                                new UserRole()
                                {
                                    Name = "Member"
                                }
                            };
                        }


#if DEBUG
                        log.InfoFormat("convert user from Helix is: {0}",
                                       (new
                        {
                            helix = helixIndv,
                            Vuser = _vusr,
                            ActivateMis = String.Format("{0}/{1}/{2}/true", ConfigurationManager.AppSettings["iMiSLoginBaseUri"]?.ToString(),
                                                        ConfigurationManager.AppSettings["iMiSLogin"], _vusr.UserName),
                        }).SerializeToString());
#endif

                        /*client
                         * .LoginToIMis(System.Web.HttpContext.Current, ConfigurationManager.AppSettings["iMiSLoginBaseUri"],
                         * ConfigurationManager.AppSettings["iMiSLogin"], ((VisitorModel)_vusr).UserName);*/


                        this.CreateOrUpdateCookie("ud", _vusr.ClientId);


                        QueryDataResponse <VisitUserModel> sfResponse = new QueryDataResponse <VisitUserModel>();
                        client.AuthenticateBy((cnn, _srv) =>
                        {
                            sfResponse = _srv.GetAuthResponse(_vusr);

                            if (sfResponse.ResponseStatus.Is(ResponseStatus.Success))
                            {
                                // login to iMIS

                                /*client
                                 * .LoginToIMis(ConfigurationManager.AppSettings["iMiSLoginBaseUri"],
                                 * ConfigurationManager.AppSettings["iMiSLogin"], ((VisitorModel)_vusr).UserName);*/

                                //this.CreateOrUpdate("hlsession", sfResponse.Result.ClientId);
                                //this.SiteAppRunner().SiteUser = FluentSiteUser<ISiteUser>.Init(sfResponse.Result).Cached(this.SessionId());
                                var _updateModel = sfResponse.Result;
                                var _cacheUser   = new GenericResultSerialized()
                                {
                                    User           = _updateModel.SerializeToString(),
                                    SessionId      = "123",//this.SessionId(),
                                    UserId         = _updateModel.UserId,
                                    Message        = "init from Auth",
                                    CreationDate   = DateTime.UtcNow,
                                    LastChangeDate = DateTime.UtcNow,
                                    // RWB 20170911 - Removed contactID ContactId = helixIndv.MembershipId,
                                    Data = helixIndv.ToJson <HelixIndividual>(),
                                };
                                //_updateModel.UpdateSessionId(this.SessionId());
                                //this.GetSetAppSiteUser(sfResponse.Result);
                                //this.SetAppSiteUser(_updateModel.UserId, _cacheUser);

#if DEBUG
                                log.Info("update user to cache:{0} by id:".Fmt(new
                                {
                                    cache    = _cacheUser,
                                    sessonid = "123",    //this.SessionId(),
                                    data     = _updateModel
                                }.SerializeToString()));
#endif
                            }
                            else
                            {
                                log.Warn("issue with auth with SF:{0}".Fmt(sfResponse.Message));
                            }
                            authUser = _vusr;
                            return(_vusr);
                        });
                    }
                    return(cl);
                });
            }

            // to show as a button then this need to be checked
            if (ShowLoginForm)
            {
                return(View("Index"));
            }
            // or last step is to redirect back

            if (!SystemManager.IsDesignMode || !SystemManager.IsPreviewMode)
            {
                //return Redirect(authUser.ReturnUrl.DefaultIfNullEmpty("/"));
                if (this.MyId().IsNullOrEmptyGuid())
                {
                    log.InfoFormat("auth-noCode:{0}", HttpContext.Request?.Url?.AbsolutePath);
                    return(Redirect("/"));
                }
                return(Redirect(returnUrl.DefaultIfNullEmpty("/")));
                //return Redirect("http://members.iafc.org/helix/MembershipSignIn/ktomko/true");
            }

            return(View("Index"));
        }