(inviterId int)
| 309 | } |
| 310 | |
| 311 | func (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 | |
| 343 | func (user *User) Update(updatePassword bool) error { |
| 344 | var err error |
no test coverage detected