mirror of
https://shylinux.com/x/community
synced 2025-04-26 01:54:05 +08:00
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package gonganxitong
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"shylinux.com/x/ice"
|
|
"shylinux.com/x/icebergs/base/aaa"
|
|
kit "shylinux.com/x/toolkits"
|
|
|
|
"shylinux.com/x/community/src/gonganxitong/model"
|
|
emails "shylinux.com/x/golang-story/src/project/email"
|
|
)
|
|
|
|
type email struct {
|
|
Tables
|
|
user user
|
|
creds emails.Creds
|
|
apply string `name:"apply username* password*" role:"void"`
|
|
reset string `name:"reset password*" help:"重置密码" role:"void"`
|
|
}
|
|
|
|
func (s email) List(m *ice.Message, arg ...string) {
|
|
if !m.IsTech() {
|
|
return
|
|
}
|
|
if msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID)); msg.Append(model.EMAIL) == "" {
|
|
m.EchoInfoButton(m.Trans("please apply email", "请申请邮箱"), s.Apply)
|
|
} else {
|
|
m.EchoInfoButton(msg.Append(model.EMAIL), s.Reset)
|
|
}
|
|
}
|
|
func (s email) Apply(m *ice.Message, arg ...string) {
|
|
defer m.ToastProcess()()
|
|
msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID))
|
|
if m.Warn(msg.Append(model.EMAIL) != "", m.Trans("email already exists", "邮箱已存在")) {
|
|
return
|
|
}
|
|
if !strings.Contains(m.Option(aaa.USERNAME), "@") {
|
|
m.Option(aaa.USERNAME, m.Option(aaa.USERNAME)+"@"+strings.Split(m.UserHost(), "://")[1])
|
|
}
|
|
m.Cmdy(s.creds, s.creds.Create, m.Option(aaa.USERNAME), m.Option(aaa.PASSWORD))
|
|
kit.If(!m.IsErr(), func() { m.Cmdy(s.user, s.user.Email, m.Option(aaa.USERNAME)) })
|
|
}
|
|
func (s email) Reset(m *ice.Message, arg ...string) {
|
|
defer m.ToastProcess()()
|
|
msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID))
|
|
if m.WarnNotFound(msg.Append(model.EMAIL) == "", model.EMAIL) {
|
|
return
|
|
}
|
|
m.Cmdy(s.creds, s.creds.Password, msg.Append(model.EMAIL), m.Option(aaa.PASSWORD))
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(email{}) }
|