2016-04-14 48 views
0

我正在嘗試爲我的項目添加一個推薦系統,因此目前我正在將其建立在this package之外。我遇到的問題是我的項目只使用accounts-google而不是帳戶密碼。該軟件包的工作方式是通過preSignUpHook爲referrerCode(/register?r=ReferralCodeHere)添加鐵路由器query parameters。我相信這隻適用於帳戶密碼不會工作時創建一個API的帳戶,如accounts-google如何在服務器鉤子中獲取鐵路由器查詢參數

我解決這個想法是使用一個Meteor.users.before.insert鉤抓住鐵路由器查詢參數和因爲我已經使用Meteor Collection Hooks的一對夫婦的其他東西把它們插入到我referrerCode領域Meteor.users。

的問題是我還沒有能夠找到一種方式來獲得服務器上的查詢參數,我希望做這樣的事情:

Meteor.users.before.insert(function(userId, doc) { 
    doc.referrerCode = Referrer._referrerCode; // Link 1 
}); 

Link 1

但這會只是未定義而已。

如果我在我的註冊頁面,它有這樣的查詢,例如:example.com/register?r=12345然後我運行Router.current().params.query.r在客戶端它返回12345。基本上我只需要將這些保存到Meteor.users中的referralCode字段,當新用戶創建帳戶時,如果引用代碼存在於註冊URL中。

我對這個有點失落。我想過把它設置爲一個Session變量,然後在.insert掛鉤中獲取它,但是這隻能在客戶端工作。我想流星法可能是最好的,但我不完全確定如何構造它。任何幫助是極大的讚賞!

回答

0
  1. 把轉診令牌到,在你的鉤子

下面,我複製了一些代碼,我曾經使用過profile

  • 使用。它是圍繞一個Invitations收集,跟蹤誰邀請誰建:

    客戶端:

    var profile = {}; 
    ... any other profile settings you've captured 
    if (token) profile.referralToken = token; 
    Accounts.createUser({ email: email, password: password, profile: profile }, function(err){ ...}) 
    

    鉤:

    if (options.profile.referralToken){ // referral case 
        var invitation = Invitations.findOne({ token: options.profile.referralToken }); 
        if (invitation) 
        user.invitationId = invitation._id; // the invitation used 
        user.invitedBy = invitation.userId; // the referring user 
        } 
        delete options.profile.referralToken; 
    } 
    return user; 
    
  • 相關問題