MCPcopy
hub / github.com/tinode/chat / onLogin

Method onLogin

server/session.go:1053–1103  ·  view source on GitHub ↗

onLogin performs steps after successful authentication.

(msgID string, timestamp time.Time, rec *auth.Rec, missing []string)

Source from the content-addressed store, hash-verified

1051
1052// onLogin performs steps after successful authentication.
1053func (s *Session) onLogin(msgID string, timestamp time.Time, rec *auth.Rec, missing []string) *ServerComMessage {
1054 var reply *ServerComMessage
1055 var params map[string]any
1056
1057 features := rec.Features
1058
1059 params = map[string]any{
1060 "user": rec.Uid.UserId(),
1061 "authlvl": rec.AuthLevel.String(),
1062 }
1063 if len(missing) > 0 {
1064 // Some credentials are not validated yet. Respond with request for validation.
1065 reply = InfoValidateCredentials(msgID, timestamp)
1066
1067 params["cred"] = missing
1068 } else {
1069 // Everything is fine, authenticate the session.
1070
1071 reply = NoErr(msgID, "", timestamp)
1072
1073 // Check if the token is suitable for session authentication.
1074 if features&auth.FeatureNoLogin == 0 {
1075 // Authenticate the session.
1076 s.uid = rec.Uid
1077 s.authLvl = rec.AuthLevel
1078 // Reset expiration time.
1079 rec.Lifetime = 0
1080 }
1081 features |= auth.FeatureValidated
1082
1083 // Record deviceId used in this session
1084 if s.deviceID != "" {
1085 if err := store.Devices.Update(rec.Uid, "", &types.DeviceDef{
1086 DeviceId: s.deviceID,
1087 Platform: s.platf,
1088 LastSeen: timestamp,
1089 Lang: s.lang,
1090 }); err != nil {
1091 logs.Warn.Println("failed to update device record", err)
1092 }
1093 }
1094 }
1095
1096 // GenSecret fails only if tokenLifetime is < 0. It can't be < 0 here,
1097 // otherwise login would have failed earlier.
1098 rec.Features = features
1099 params["token"], params["expires"], _ = store.Store.GetLogicalAuthHandler("token").GenSecret(rec)
1100
1101 reply.Ctrl.Params = params
1102 return reply
1103}
1104
1105func (s *Session) get(msg *ClientComMessage) {
1106 // Expand topic name.

Callers 2

loginMethod · 0.95
replyCreateUserFunction · 0.80

Calls 8

InfoValidateCredentialsFunction · 0.85
NoErrFunction · 0.85
UserIdMethod · 0.80
PrintlnMethod · 0.80
UpdateMethod · 0.65
GenSecretMethod · 0.65
GetLogicalAuthHandlerMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected