| @@ -5,7 +5,6 @@ import ( | |||||
| "strings" | "strings" | ||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/auth" | |||||
| "code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
| "code.gitea.io/gitea/modules/context" | "code.gitea.io/gitea/modules/context" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| @@ -55,23 +54,30 @@ func InviationTpl(ctx *context.Context) { | |||||
| ctx.HTML(200, tplInvitation) | ctx.HTML(200, tplInvitation) | ||||
| } | } | ||||
| func RegisteUserByInvitaionCode(form auth.RegisterForm, newUserId int64) error { | |||||
| invitationcode := form.InvitaionCode | |||||
| func RegisteUserByInvitaionCode(invitationcode string, newUserId int64) error { | |||||
| user := parseInvitaionCode(invitationcode) | |||||
| if user == nil { | |||||
| return errors.New("The invitated user not existed.") | |||||
| } | |||||
| re := models.QueryInvitaionByPhone(form.PhoneNumber) | |||||
| if re != nil { | |||||
| if len(re) > 0 { | |||||
| log.Info("The phone has been invitated. so ingore it.") | |||||
| return errors.New("The phone has been invitated.") | |||||
| if user.PhoneNumber != "" { | |||||
| re := models.QueryInvitaionByPhone(user.PhoneNumber) | |||||
| if re != nil { | |||||
| if len(re) > 0 { | |||||
| log.Info("The phone has been invitated. so ingore it.") | |||||
| return errors.New("The phone has been invitated.") | |||||
| } | |||||
| } | } | ||||
| } else { | |||||
| log.Info("the phone number is null. user name=" + user.Name) | |||||
| } | } | ||||
| user := parseInvitaionCode(invitationcode) | |||||
| invitation := &models.Invitation{ | invitation := &models.Invitation{ | ||||
| SrcUserID: user.ID, | SrcUserID: user.ID, | ||||
| UserID: newUserId, | UserID: newUserId, | ||||
| Phone: form.PhoneNumber, | |||||
| Phone: user.PhoneNumber, | |||||
| } | } | ||||
| err := models.InsertInvitaion(invitation) | err := models.InsertInvitaion(invitation) | ||||
| if err != nil { | if err != nil { | ||||
| log.Info("insert error," + err.Error()) | log.Info("insert error," + err.Error()) | ||||