mirror of
https://shylinux.com/x/community
synced 2025-04-28 02:32:01 +08:00
51 lines
1.7 KiB
Go
51 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 {
|
|
user user
|
|
portal portal
|
|
Creds emails.Creds
|
|
apply string `name:"apply username* password*"`
|
|
reset string `name:"reset password*" help:"重置密码"`
|
|
}
|
|
|
|
func (s email) Init(m *ice.Message, arg ...string) {
|
|
s.portal.Show(m)
|
|
}
|
|
func (s email) List(m *ice.Message, arg ...string) {
|
|
if msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID)); len(msg.Append(model.EMAIL)) < 10 {
|
|
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) {
|
|
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)+"@"+m.UserWeb().Hostname())
|
|
}
|
|
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)) })
|
|
kit.If(!m.IsErr(), func() { m.ToastSuccess() })
|
|
}
|
|
func (s email) Reset(m *ice.Message, arg ...string) {
|
|
msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID))
|
|
m.Cmdy(s.Creds, s.Creds.Password, msg.Append(model.EMAIL), m.Option(aaa.PASSWORD))
|
|
kit.If(!m.IsErr(), func() { m.ToastSuccess() })
|
|
}
|
|
|
|
func init() { ice.Cmd(prefixKey(), email{}) }
|