replySetCred adds or validates user credentials such as email and phone numbers.
(sess *Session, asUid types.Uid, authLevel auth.Level, msg *ClientComMessage)
| 3035 | |
| 3036 | // replySetCred adds or validates user credentials such as email and phone numbers. |
| 3037 | func (t *Topic) replySetCred(sess *Session, asUid types.Uid, authLevel auth.Level, msg *ClientComMessage) error { |
| 3038 | now := types.TimeNow() |
| 3039 | set := msg.Set |
| 3040 | |
| 3041 | if t.cat != types.TopicCatMe { |
| 3042 | sess.queueOut(ErrOperationNotAllowedReply(msg, now)) |
| 3043 | return errors.New("invalid topic category for updating credentials") |
| 3044 | } |
| 3045 | |
| 3046 | var err error |
| 3047 | var tags []string |
| 3048 | creds := []MsgCredClient{*set.Cred} |
| 3049 | if set.Cred.Response != "" { |
| 3050 | // Credential is being validated. Return an arror if response is invalid. |
| 3051 | _, tags, err = validatedCreds(asUid, authLevel, creds, true) |
| 3052 | } else { |
| 3053 | // Credential is being added or updated. |
| 3054 | tmpToken, _, _ := store.Store.GetLogicalAuthHandler("token").GenSecret(&auth.Rec{ |
| 3055 | Uid: asUid, |
| 3056 | AuthLevel: auth.LevelNone, |
| 3057 | Lifetime: auth.Duration(time.Hour * 24), |
| 3058 | Features: auth.FeatureNoLogin, |
| 3059 | }) |
| 3060 | _, tags, err = addCreds(asUid, creds, nil, sess.lang, tmpToken) |
| 3061 | } |
| 3062 | |
| 3063 | if tags != nil { |
| 3064 | t.tags = tags |
| 3065 | t.presSubsOnline("tags", "", nilPresParams, nilPresFilters, "") |
| 3066 | } |
| 3067 | |
| 3068 | sess.queueOut(decodeStoreErrorExplicitTs(err, set.Id, t.original(asUid), now, msg.Timestamp, nil)) |
| 3069 | |
| 3070 | return err |
| 3071 | } |
| 3072 | |
| 3073 | // replyGetAux returns topic's auxiliary set of key-value pairs. |
| 3074 | func (t *Topic) replyGetAux(sess *Session, asUid types.Uid, msg *ClientComMessage) error { |
no test coverage detected