MCPcopy Create free account
hub / github.com/53AI/53AIHub / Create

Method Create

api/model/user.go:58–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56)
57
58func (user *User) Create() error {
59 var err error
60 if user.Eid == 0 {
61 return errors.New("eid is empty")
62 }
63 // check if username exists
64 var count int64
65 // DB.Model(&User{}).Where("eid = ? AND username = ?", user.Eid, user.Username).Count(&count)
66 // if count > 0 {
67 // return errors.New("username already exists")
68 // }
69
70 if user.Mobile != "" {
71 // check if mobile exists
72 DB.Model(&User{}).Where("eid =? AND mobile =?", user.Eid, user.Mobile).Count(&count)
73 if count > 0 {
74 return errors.New("mobile already exists")
75 }
76 }
77
78 if user.Email != "" {
79 // check if email exists
80 DB.Model(&User{}).Where("eid =? AND email =?", user.Eid, user.Email).Count(&count)
81 if count > 0 {
82 return errors.New("email already exists")
83 }
84 }
85
86 if user.Salt == "" {
87 user.Salt = helper.RandomString(6)
88 }
89 if user.Password != "" {
90 user.Password, err = helper.PasswordHash(user.Password, user.Salt)
91 if err != nil {
92 return err
93 }
94 } else {
95 return errors.New("password is empty")
96 }
97
98 result := DB.Create(user)
99 if result.Error != nil {
100 return result.Error
101 }
102
103 user.AccessToken, err = jwt.UserGenerateJWT(user.UserID, user.Eid)
104 if err != nil {
105 return err
106 }
107
108 err = DB.Model(user).Updates(user).Error
109
110 return err
111}
112
113func (user *User) Update(updatePassword bool) error {
114 updateMap := map[string]interface{}{

Callers 3

PasswordRegisterFunction · 0.95
EnterpriseAddUserFunction · 0.95
CreateVisitorUserFunction · 0.45

Calls 1

NewMethod · 0.45

Tested by

no test coverage detected