Exemplo n.º 1
0
        public int CreateAccountWithFacebook(string betapassword, string signature, string[] names, string[] values)
        {
            TransitFacebookLogin t_facebook = TryLoginFacebook(signature, names, values);
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;

                string s = ManagedConfiguration.GetValue(session, "SnCore.Beta.Password", string.Empty);
                if (s != betapassword)
                {
                    throw new ManagedAccount.AccessDeniedException();
                }

                ManagedAccount acct = new ManagedAccount(session);

                // fetch account information
                Facebook.Session.ConnectSession facebookSession = new Facebook.Session.ConnectSession(
                    ManagedConfiguration.GetValue(session, "Facebook.APIKey", ""),
                    ManagedConfiguration.GetValue(session, "Facebook.Secret", ""));

                TransitAccount ta = new TransitAccount();
                NameValueCollectionSerializer facebookCookies = new NameValueCollectionSerializer(names, values);
                facebookSession.SessionKey = facebookCookies.Collection["session_key"];
                facebookSession.UserId = t_facebook.FacebookAccountId;
                Facebook.Rest.Api facebookAPI = new Facebook.Rest.Api(facebookSession);
                Facebook.Schema.user user = facebookAPI.Users.GetInfo();
                ta.Name = user.name;
                DateTime birthday = DateTime.Today;
                DateTime.TryParse(user.birthday_date, out birthday);
                ta.Birthday = birthday;
                acct.CreateWithFacebook(t_facebook.FacebookAccountId, user.proxied_email, 
                    ta, ManagedAccount.GetAdminSecurityContext(session));

                if (user.current_location != null)
                {
                    ta.City = user.current_location.city;

                    int country_id;
                    if (ManagedCountry.TryGetCountryId(session, user.current_location.country, out country_id))
                        ta.Country = user.current_location.country;
                    
                    int state_id;
                    if (ManagedState.TryGetStateId(session, user.current_location.state, user.current_location.country, out state_id))
                        ta.State = user.current_location.state;
                }

                if (user.picture_big != null)
                {
                    TransitAccountPicture t_picture = new TransitAccountPicture();
                    t_picture.AccountId = acct.Id;
                    ThumbnailBitmap bitmap = new ThumbnailBitmap(new Bitmap(user.picture_big));
                    t_picture.Bitmap = bitmap.Bitmap;
                    t_picture.Thumbnail = bitmap.Thumbnail;
                    t_picture.Name = user.pic;
                    ManagedAccountPicture m_picture = new ManagedAccountPicture(session);
                    m_picture.CreateOrUpdate(t_picture, ManagedAccount.GetAdminSecurityContext(session));
                }

                SnCore.Data.Hibernate.Session.Flush();
                return acct.Id;
            }
        }
Exemplo n.º 2
0
 public void MoveAccountPicture(string ticket, int id, int disp)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedAccountPicture m_instance = new ManagedAccountPicture(session, id);
         m_instance.Move(sec, disp);
     }
 }