MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / Insert

Method Insert

model/user.go:311–341  ·  view source on GitHub ↗
(inviterId int)

Source from the content-addressed store, hash-verified

309}
310
311func (user *User) Insert(inviterId int) error {
312 var err error
313 if user.Password != "" {
314 user.Password, err = common.Password2Hash(user.Password)
315 if err != nil {
316 return err
317 }
318 }
319 user.Quota = common.QuotaForNewUser
320 //user.SetAccessToken(common.GetUUID())
321 user.AffCode = common.GetRandomString(4)
322 result := DB.Create(user)
323 if result.Error != nil {
324 return result.Error
325 }
326 if common.QuotaForNewUser > 0 {
327 RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("新用户注册赠送 %s", common.LogQuota(common.QuotaForNewUser)))
328 }
329 if inviterId != 0 {
330 if common.QuotaForInvitee > 0 {
331 _ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true)
332 RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", common.LogQuota(common.QuotaForInvitee)))
333 }
334 if common.QuotaForInviter > 0 {
335 //_ = IncreaseUserQuota(inviterId, common.QuotaForInviter)
336 RecordLog(inviterId, LogTypeSystem, fmt.Sprintf("邀请用户赠送 %s", common.LogQuota(common.QuotaForInviter)))
337 _ = inviteUser(inviterId)
338 }
339 }
340 return nil
341}
342
343func (user *User) Update(updatePassword bool) error {
344 var err error

Callers 6

GitHubOAuthFunction · 0.95
OidcAuthFunction · 0.95
LinuxdoOAuthFunction · 0.95
RegisterFunction · 0.95
CreateUserFunction · 0.95
WeChatAuthFunction · 0.95

Calls 6

Password2HashFunction · 0.92
GetRandomStringFunction · 0.92
LogQuotaFunction · 0.92
RecordLogFunction · 0.85
IncreaseUserQuotaFunction · 0.85
inviteUserFunction · 0.85

Tested by

no test coverage detected