protected void Page_Load(object sender, EventArgs e)
        {
            if (string.Equals("localhost", this.Request.Headers["Host"].Split(':')[0], StringComparison.OrdinalIgnoreCase))
            {
                this.localhostDoesNotWorkPanel.Visible = true;
                var builder = new UriBuilder(this.publicLink.NavigateUrl);
                builder.Port = this.Request.Url.Port;
                this.publicLink.NavigateUrl = builder.Uri.AbsoluteUri;
                this.publicLink.Text        = builder.Uri.AbsoluteUri;
            }
            else
            {
                IAuthorizationState authorization = windowsLiveClient.ProcessUserAuthorization();
                if (authorization == null)
                {
                    // Kick off authorization request
                    windowsLiveClient.RequestUserAuthorization(scope: new[] { WindowsLiveClient.Scopes.Basic });                     // this scope isn't even required just to log in

                    // alternatively you can ask for more information
                    // windowsLiveClient.RequestUserAuthorization(scope: new[] { WindowsLiveClient.Scopes.SignIn, WindowsLiveClient.Scopes.Emails, WindowsLiveClient.Scopes.Birthday });
                }
                else
                {
                    IOAuth2Graph oauth2Graph = windowsLiveClient.GetGraph(authorization);

                    this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
                }
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RegisterAsyncTask(
                new PageAsyncTask(
                    async ct => {
                IAuthorizationState authorization = await facebookClient.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), ct);
                if (authorization == null)
                {
                    // Kick off authorization request
                    var request = await facebookClient.PrepareRequestUserAuthorizationAsync(cancellationToken: ct);
                    await request.SendAsync(new HttpContextWrapper(Context), ct);
                    this.Context.Response.End();

                    // alternatively you can ask for more information
                    // facebookClient.RequestUserAuthorization(scope: new[] { FacebookClient.Scopes.Email, FacebookClient.Scopes.UserBirthday });
                }
                else
                {
                    IOAuth2Graph oauth2Graph = await facebookClient.GetGraphAsync(authorization, cancellationToken: ct);
                    //// IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization, new[] { FacebookGraph.Fields.Defaults, FacebookGraph.Fields.Email, FacebookGraph.Fields.Picture, FacebookGraph.Fields.Birthday });

                    this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
                }
            }));
        }
 protected void page_load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             IAuthorizationState authorization = googleClient.ProcessUserAuthorization();
             if (authorization == null)
             {
                 googleClient.RequestUserAuthorization(scope: new[] { "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/plus.me" });
                 googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.UserInfo.Profile, GoogleClient.Scopes.UserInfo.Email });
             }
             else
             {
                 UserCollection list        = UserCollection.GetUserCollection();
                 IOAuth2Graph   oauth2Graph = googleClient.GetGraph(authorization);
                 string         _email      = HttpUtility.HtmlEncode(oauth2Graph.Email);
                 User           user        = list.Single(a => a.Email == _email);
                 FormsAuthentication.SetAuthCookie(user.Name, true);
                 Response.Redirect("~/Systems/Default.aspx");
             }
         }
         catch (Exception ex) { }
     }
 }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IAuthorizationState authorization = googleClient.ProcessUserAuthorization();

            if (authorization == null)
            {
                // Kick off authorization request
                googleClient.RequestUserAuthorization();

                // alternatively you can ask for more information
                // googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.UserInfo.Profile, GoogleClient.Scopes.UserInfo.Email });
            }
            else
            {
                IOAuth2Graph oauth2Graph = googleClient.GetGraph(authorization);

                this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();

            if (authorization == null)
            {
                // Kick off authorization request
                facebookClient.RequestUserAuthorization();

                // alternatively you can ask for more information
                // facebookClient.RequestUserAuthorization(scope: new[] { FacebookClient.Scopes.Email, FacebookClient.Scopes.UserBirthday });
            }
            else
            {
                IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization);
                //// IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization, new[] { FacebookGraph.Fields.Defaults, FacebookGraph.Fields.Email, FacebookGraph.Fields.Picture, FacebookGraph.Fields.Birthday });

                this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
            }
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RegisterAsyncTask(
                new PageAsyncTask(
                    async ct => {
                if (string.Equals("localhost", this.Request.Headers["Host"].Split(':')[0], StringComparison.OrdinalIgnoreCase))
                {
                    this.localhostDoesNotWorkPanel.Visible = true;
                    var builder  = new UriBuilder(this.publicLink.NavigateUrl);
                    builder.Port = this.Request.Url.Port;
                    this.publicLink.NavigateUrl = builder.Uri.AbsoluteUri;
                    this.publicLink.Text        = builder.Uri.AbsoluteUri;
                }
                else
                {
                    IAuthorizationState authorization = await windowsLiveClient.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), ct);
                    if (authorization == null)
                    {
                        // Kick off authorization request
                        var request = await windowsLiveClient.PrepareRequestUserAuthorizationAsync(
                            scopes: new[] { WindowsLiveClient.Scopes.Basic },                                             // this scope isn't even required just to log in
                            cancellationToken: ct);
                        await request.SendAsync(new HttpContextWrapper(Context), ct);
                        this.Context.Response.End();

                        // alternatively you can ask for more information
                        // windowsLiveClient.RequestUserAuthorization(scope: new[] { WindowsLiveClient.Scopes.SignIn, WindowsLiveClient.Scopes.Emails, WindowsLiveClient.Scopes.Birthday });
                    }
                    else
                    {
                        IOAuth2Graph oauth2Graph = await windowsLiveClient.GetGraphAsync(authorization, cancellationToken: ct);

                        this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
                    }
                }
            }));
        }
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string ReturnURL        = string.Empty;
            string userRole         = string.Empty;
            Uri    currentDomainURL = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);

            string value = Utility.GetQueryStringValueByKey(Request, "type");

            if (!IsPostBack)
            {
                if (value == "s")
                {
                    ReturnURL = "/Student/Student_Profile.aspx";
                    userRole  = "student";
                }
                else if (value == "l")
                {
                    ReturnURL = "/Land_load/Land_load_Profile.aspx";
                    userRole  = "landlord";
                }
                else
                {
                    ReturnURL = "~/";
                }
            }

            try
            {
                IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();

                User user = new User();
                RHP.StudentManagement.Student student = new RHP.StudentManagement.Student();

                Landlord landload = new Landlord();

                if (authorization == null)
                {
                    SendEmail("FBReturn URL", string.Format("Return URL: {0}, App Id: {1}, App Secret: {2}", currentDomainURL.ToString(),
                                                            facebookClient.ClientIdentifier.ToString(), facebookClient.ClientCredentialApplicator.ToString()));
                    facebookClient.RequestUserAuthorization(scope: new[] { FBClient.Scopes.Email }, returnTo: currentDomainURL);
                }
                else// if (authorization.Scope.Count > 0)
                {
                    string accessCode = string.Empty;
                    if (authorization != null && authorization.AccessToken != null)
                    {
                        accessCode = Uri.EscapeDataString(authorization.AccessToken);
                    }

                    IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization, new[] { FBGraph.Fields.Defaults, FBGraph.Fields.Email, FBGraph.Fields.Picture });

                    //Todo: Register the user here if not an existing member.
                    user.FBid = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.Id)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.Id);

                    user.FirstName           = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.FirstName)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.FirstName);
                    user.LastName            = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.LastName)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.LastName);
                    user.Email               = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.Email)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.Email);
                    user.PersonalEmail       = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.Email)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.Email);
                    user.FBAccessToken       = string.IsNullOrEmpty(authorization.AccessToken) ? string.Empty : authorization.AccessToken;
                    user.FBProfilePictureURL = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.AvatarUrl)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.AvatarUrl);
                    user.Gender              = string.IsNullOrEmpty(HttpUtility.HtmlEncode(oauth2Graph.Gender)) ? string.Empty : HttpUtility.HtmlEncode(oauth2Graph.Gender);
                    user.IsFBUser            = true;
                    user.Password            = user.FBid;
                    user.UserName            = user.FBid;
                    user.Question            = "Are you FB User ?";
                    user.Answer              = "FB" + user.FBid;

                    if (user.IsExistingFbUser(user.FBid))
                    {
                        // authanticate fbuser get userneame and pwd
                        // get user from fbid (username)
                        // stringpassword = membership

                        user.UserName = user.GetFBUsernameByFBId(user.FBid);

                        if (user.AuthenticateUser())
                        {
                            try
                            {
                                Session[Constants.SESSION_LOGGED_USER] = user;
                                user.RedirectUserFromLogin(false);
                            }
                            catch (Exception ex)
                            {
                                user.LogOut();
                            }
                        }
                        else
                        {
                            user.LogOut();
                        }
                    }
                    else
                    {
                        if (user.IsUserEmailExist(user.Email))
                        {
                            //Todo need to handle this part correctly.
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "Redirect", "window.onload = function(){ alert('" + Messages.EmailExist + "'); window.location = '/Login.aspx'; }", true);
                        }
                        else
                        {
                            bool   boolMembershipUserCreated = false;
                            object objCreateMembershipUser   = new object();

                            user.UserId             = Guid.NewGuid();
                            objCreateMembershipUser = user.AddMembershipPartialUser(user.UserName, user.Password, user.Email, user.Question, user.Answer, true, user.UserId.Value, userRole);

                            bool.TryParse(objCreateMembershipUser.ToString(), out boolMembershipUserCreated);

                            if (boolMembershipUserCreated)
                            {
                                FormsAuthentication.SetAuthCookie(user.UserName, false);
                                user.UpdatedBy = user.UserId.HasValue ? user.UserId.Value : Guid.Parse(Membership.GetUser().ProviderUserKey.ToString());
                                user.CreatedBy = user.UserId.HasValue ? user.UserId.Value : Guid.Parse(Membership.GetUser().ProviderUserKey.ToString());

                                if (user.Save())
                                {
                                    Session[Constants.SESSION_LOGGED_USER] = user;
                                    MembershipUser newUser = Membership.GetUser(user.UserName);
                                    user.RedirectUserFromLogin(true);
                                }
                                else
                                {
                                    user.LogOut();
                                    //Todo delete membership user from tables
                                    Response.Redirect("~/Login.aspx", false);
                                }
                            }
                            else
                            {
                                user.LogOut();
                                Response.Redirect("~/Login.aspx", false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string emailText = String.Format("Message:{0}, Source:{1}, StackTrace:{2}", ex.Message, ex.Source, ex.StackTrace);
                SendEmail("FB Exception", emailText);
                throw ex;
            }
        }