Merge remote-tracking branch 'origin/tuoyun' into tuoyun

This commit is contained in:
wenxu12345
2022-02-11 18:49:27 +08:00
11 changed files with 166 additions and 311 deletions
+1
View File
@@ -285,6 +285,7 @@ type config struct {
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
}
SuperCode string `yaml:"superCode"`
CodeTTL int `yaml:"codeTTL"`
Mail struct {
Title string `yaml:"title"`
SenderMail string `yaml:"senderMail"`
+16 -8
View File
@@ -68,14 +68,22 @@ var (
)
const (
NoError = 0
FormattingError = 10001
DatabaseError = 10002
LogicalError = 10003
ServerError = 10004
HttpError = 10005
IoError = 10006
IntentionalError = 10007
NoError = 0
FormattingError = 10001
HasRegistered = 10002
NotRegistered = 10003
PasswordErr = 10004
GetIMTokenErr = 10005
RepeatSendCode = 10006
MailSendCodeErr = 10007
SmsSendCodeErr = 10008
CodeInvalidOrExpired = 10009
RegisterFailed = 10010
DatabaseError = 10002
ServerError = 10004
HttpError = 10005
IoError = 10006
IntentionalError = 10007
)
func (e *ErrInfo) Error() string {
+6 -1
View File
@@ -2,6 +2,12 @@ package db
import "time"
type Register struct {
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
Ex string `gorm:"column:ex;size:1024" json:"ex"`
}
//
//message FriendInfo{
//string OwnerUserID = 1;
@@ -183,7 +189,6 @@ type ChatLog struct {
ContentType int32 `gorm:"column:content_type" json:"contentType"`
Content string `gorm:"column:content;type:varchar(1000)" json:"content"`
Status int32 `gorm:"column:status" json:"status"`
Seq uint32 `gorm:"column:seq;index:index_seq;default:0" json:"seq"`
SendTime time.Time `gorm:"column:send_time" json:"sendTime"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
+9 -1
View File
@@ -58,7 +58,7 @@ func initMysqlDB() {
&GroupMember{},
&GroupRequest{},
&User{},
&Black{}, &ChatLog{})
&Black{}, &ChatLog{}, &Register{})
db.Set("gorm:table_options", "CHARSET=utf8")
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
@@ -96,6 +96,14 @@ func initMysqlDB() {
log.NewInfo("CreateTable Black")
db.CreateTable(&Black{})
}
if !db.HasTable(&ChatLog{}) {
log.NewInfo("CreateTable Black")
db.CreateTable(&ChatLog{})
}
if !db.HasTable(&Register{}) {
log.NewInfo("CreateTable Black")
db.CreateTable(&Register{})
}
return
@@ -5,60 +5,25 @@ import (
_ "github.com/jinzhu/gorm"
)
type GetRegisterParams struct {
Account string `json:"account"`
}
type Register struct {
Account string `gorm:"column:account"`
Password string `gorm:"column:password"`
}
func GetRegister(params *GetRegisterParams) (Register, error, int64) {
var r Register
func GetRegister(account string) (*db.Register, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return r, err, 0
return nil, err
}
result := dbConn.
Where(&Register{Account: params.Account}).
Find(&r)
return r, result.Error, result.RowsAffected
var r db.Register
return &r, dbConn.Table("registers").Where("account = ?",
account).Take(&r).Error
}
type SetPasswordParams struct {
Account string `json:"account"`
Password string `json:"password"`
}
func SetPassword(params *SetPasswordParams) (Register, error) {
r := Register{
Account: params.Account,
Password: params.Password,
func SetPassword(account, password, ex string) error {
r := db.Register{
Account: account,
Password: password,
Ex: ex,
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return r, err
return err
}
return dbConn.Table("registers").Create(&r).Error
result := dbConn.Create(&r)
return r, result.Error
}
func Login(params *Register) int64 {
var r Register
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 3
}
result := dbConn.
Where(&Register{Account: params.Account}).
Find(&r)
if result.Error != nil && result.RowsAffected == 0 {
return 1
}
if r.Password != params.Password {
return 2
}
return 0
}
+14
View File
@@ -7,6 +7,7 @@ import (
)
const (
registerAccountTempCode = "REGISTER_ACCOUNT_TEMP_CODE"
userIncrSeq = "REDIS_USER_INCR_SEQ:" // user incr seq
appleDeviceToken = "DEVICE_TOKEN"
userMinSeq = "REDIS_USER_MIN_SEQ:"
@@ -33,6 +34,19 @@ func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (inte
return con.Do(cmd, params...)
}
func (d *DataBases) JudgeAccountEXISTS(account string) (bool, error) {
key := registerAccountTempCode + account
return redis.Bool(d.Exec("EXISTS", key))
}
func (d *DataBases) SetAccountCode(account string, code, ttl int) (err error) {
key := registerAccountTempCode + account
_, err = d.Exec("Set", key, code, ttl)
return err
}
func (d *DataBases) GetAccountCode(account string) (string, error) {
key := userIncrSeq + account
return redis.String(d.Exec("GET", key))
}
//Perform seq auto-increment operation of user messages
func (d *DataBases) IncrUserSeq(uid string) (uint64, error) {