Esempio n. 1
0
        /// <summary>
        /// Called from authenticated facebook client 'accounts.climbfind.com' and the mobile app
        /// </summary>
        /// <param name="email"></param>
        /// <param name="fullName"></param>
        /// <param name="password"></param>
        /// <param name="nationality"></param>
        /// <param name="isMale"></param>
        /// <param name="facebookID"></param>
        /// <param name="facebookToken"></param>
        /// <param name="signUpOrigin"></param>
        /// <returns></returns>
        public Profile CreateUser(string email, string fullName, string password, byte nationality, bool isMale, long?facebookID,
                                  string facebookToken, string signUpOrigin)
        {
            try
            {
                bool detailsValid = true; //-- todo, perform some sort of validation on incoming details
                if (detailsValid)
                {
                    MembershipCreateStatus createStatus;
                    var mUser = Membership.CreateUser(email, password, email, null, null, true, null, out createStatus);

                    if (createStatus != MembershipCreateStatus.Success)
                    {
                        throw new MembershipCreateUserException(createStatus);
                    }
                    else
                    {
                        var userID = new Guid(mUser.ProviderUserKey.ToString());

                        var user = CreateProfile(new Profile()
                        {
                            ID            = userID,
                            CountryID     = nationality,
                            Email         = email,
                            FullName      = fullName,
                            IsMale        = isMale,
                            FacebookID    = facebookID,
                            FacebookToken = facebookToken,
                            PrivacyAllowNewConversations = true,
                            PrivacyShowFeed             = true,
                            PrivacyShowHistory          = true,
                            PrivacyPostsDefaultIsPublic = true,
                            PrivacyShowInSearch         = true,
                            PrivacyShowOnPartnerSites   = true
                        });

                        var traceMsg = string.Format("{0} created an account via {1}", fullName, signUpOrigin);
                        if (facebookID.HasValue)
                        {
                            traceMsg += " w fbid: " + facebookID.Value.ToString();
                        }
                        CfTrace.Information(TraceCode.UserCreateAccount, traceMsg);
                        MailMan.SendAppEvent(TraceCode.UserCreateAccount, traceMsg, email, userID, "*****@*****.**", true);

                        try
                        {
                            if (facebookID.HasValue)
                            {
                                var originalImgUrl = string.Format("http://graph.facebook.com/{0}/picture?type=large", facebookID.Value);
                                using (Stream imgStream = new ImageDownloader().DownloadImageAsStream(originalImgUrl))
                                {
                                    //-- Note this function automatically updates the user object in the database
                                    SaveProfileAvatarPicFrom3rdPartSource(imgStream, user);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            CfTrace.Error(ex);
                        }

                        return(user);
                    }
                }
                else
                {
                    throw new Exception("Sign up detail invalid from origin: " + signUpOrigin);
                }
            }
            catch (Exception ex) //-- extra logging / safety as we really don't want this code to screw up and if it does be better know about it!
            {
                if (!ex.Message.Contains("form required for an e-mail address") && !ex.Message.Contains("username is already in use"))
                {
                    CfTrace.Error(ex);
                }
                throw ex;
            }
        }
Esempio n. 2
0
 void MemcachedServer_Crashed(object sender, EventArgs e)
 {
     MailMan.SendAppEvent(TraceCode.AppEnd, "Memcached server failed!! Recycling cf.CacheServer worker role", "*****@*****.**", Stgs.SystemID, "*****@*****.**", false);
     RoleEnvironment.RequestRecycle();
 }
Esempio n. 3
0
        /// <summary>
        /// Used:
        /// 1) In the case when the facebook ID does not match a profile, but the user is signed in to facebook (we check if we can connect the accounts)
        /// 2) When the user logs in with their CF3 email/password to a client (Accounts Server, PG Site, CF4, Mobile App) for the first time
        /// </summary>
        public Profile GetUserByEmailAndCreateCf4ProfileIfNotExists(string email)
        {
            var profile = profileRepo.GetProfileByEmail(email);

            if (profile == null)
            {
                var cf3Profile = new cf.DataAccess.cf3.ClimberProfileDA().GetClimberProfile(email);
                if (cf3Profile != default(Cf3Profile))
                {
                    var    idStr    = cf3Profile.ID.ToString();
                    string userName = idStr.Substring(idStr.Length - 9, 8);

                    profile = new Profile()
                    {
                        ID                           = cf3Profile.ID,
                        CountryID                    = byte.Parse(cf3Profile.Nationality.ToString()),
                        DisplayNameTypeID            = 0,
                        Email                        = email,
                        FullName                     = cf3Profile.FullName,
                        IsMale                       = cf3Profile.IsMale.Value,
                        NickName                     = cf3Profile.NickName,
                        UserName                     = userName,
                        ContactNumber                = cf3Profile.ContractPhoneNumber,
                        PrivacyAllowNewConversations = true,
                        PrivacyShowFeed              = true,
                        PrivacyShowHistory           = true,
                        PrivacyPostsDefaultIsPublic  = true,
                        PrivacyShowInSearch          = true,
                        PrivacyShowOnPartnerSites    = true
                    };

                    profileRepo.Create(profile);

                    var traceMsg = string.Format("{0} upgraded cf3 account", cf3Profile.FullName);
                    CfTrace.Information(TraceCode.UserCreateAccount, traceMsg);
                    MailMan.SendAppEvent(TraceCode.UserCreateAccount, traceMsg, email, cf3Profile.ID, "*****@*****.**", true);

                    try
                    {
                        var originalImgUrl = GetCf3ProfilePicFullSizeUrl(cf3Profile.ID, cf3Profile.ProfilePictureFile);
                        if (!string.IsNullOrWhiteSpace(originalImgUrl))
                        {
                            using (Stream imgStream = new ImageDownloader().DownloadImageAsStream(originalImgUrl))
                            {
                                if (imgStream == null)
                                {
                                    throw new ArgumentException("Cf3 image stream is null for: " + originalImgUrl);
                                }
                                if (profile == null)
                                {
                                    throw new ArgumentException("Profile is null...");
                                }

                                //-- Note this function automatically updates the user object in the database
                                SaveProfileAvatarPicFrom3rdPartSource(imgStream, profile);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        CfTrace.Error(ex);
                    }
                }
            }

            return(profile);
        }
Esempio n. 4
0
 void ServiceHost_RefreshNotificationRecieved(object sender, RefreshMessage e)
 {
     MailMan.SendAppEvent(TraceCode.AppBuildCache, "Receive refresh request notification, refreshing cache server", "*****@*****.**", Guid.Empty, "*****@*****.**", false);
     PopuluteCfCacheIndex();
 }