MCPcopy Create free account
hub / github.com/daodst/chat / acc

Method acc

server/session.go:372–452  ·  view source on GitHub ↗

Account creation

(msg *ClientComMessage)

Source from the content-addressed store, hash-verified

370
371// Account creation
372func (s *Session) acc(msg *ClientComMessage) {
373 if msg.Acc.Auth == nil {
374 s.QueueOut(ErrMalformed(msg.Acc.Id, "", msg.timestamp))
375 return
376 } else if len(msg.Acc.Auth) == 0 {
377 s.QueueOut(ErrAuthUnknownScheme(msg.Acc.Id, "", msg.timestamp))
378 return
379 }
380
381 if msg.Acc.User == "new" {
382 // Request to create a new account
383 for _, auth := range msg.Acc.Auth {
384 if auth.Scheme == "basic" {
385 var private interface{}
386 var user types.User
387 if msg.Acc.Init != nil {
388 user.Access.Auth = DEFAULT_AUTH_ACCESS
389 user.Access.Anon = DEFAULT_ANON_ACCESS
390
391 if msg.Acc.Init.DefaultAcs != nil {
392 if msg.Acc.Init.DefaultAcs.Auth != "" {
393 user.Access.Auth.UnmarshalText([]byte(msg.Acc.Init.DefaultAcs.Auth))
394 }
395 if msg.Acc.Init.DefaultAcs.Anon != "" {
396 user.Access.Anon.UnmarshalText([]byte(msg.Acc.Init.DefaultAcs.Anon))
397 }
398 }
399 user.Public = msg.Acc.Init.Public
400 private = msg.Acc.Init.Private
401 }
402 _, err := store.Users.Create(s.appid, &user, auth.Scheme, auth.Secret, private)
403 if err != nil {
404 if err.Error() == "duplicate credential" {
405 s.QueueOut(ErrDuplicateCredential(msg.Acc.Id, "", msg.timestamp))
406 } else {
407 s.QueueOut(ErrUnknown(msg.Acc.Id, "", msg.timestamp))
408 }
409 return
410 }
411
412 reply := NoErrCreated(msg.Acc.Id, "", msg.timestamp)
413 info := &MsgTopicInfo{
414 CreatedAt: &user.CreatedAt,
415 UpdatedAt: &user.UpdatedAt,
416 DefaultAcs: &MsgDefaultAcsMode{
417 Auth: user.Access.Auth.String(),
418 Anon: user.Access.Anon.String()},
419 Public: user.Public,
420 Private: private}
421
422 reply.Ctrl.Params = map[string]interface{}{
423 "uid": user.Uid().UserId(),
424 "info": info,
425 }
426 s.QueueOut(NoErr(msg.Acc.Id, "", msg.timestamp))
427 } else {
428 s.QueueOut(ErrAuthUnknownScheme(msg.Acc.Id, "", msg.timestamp))
429 return

Callers 1

dispatchMethod · 0.95

Calls 13

QueueOutMethod · 0.95
ErrMalformedFunction · 0.85
ErrAuthUnknownSchemeFunction · 0.85
ErrDuplicateCredentialFunction · 0.85
ErrUnknownFunction · 0.85
NoErrCreatedFunction · 0.85
NoErrFunction · 0.85
ErrPermissionDeniedFunction · 0.85
ChangeAuthCredentialMethod · 0.80
UnmarshalTextMethod · 0.45
CreateMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected