From a2fbb246151ce722a30d932dd73a9ecc76b020e9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Mar 2014 09:24:02 -0400 Subject: [PATCH] Add active page --- modules/auth/mail.go | 17 +++++++++++++++++ modules/middleware/auth.go | 4 ++++ routers/user/user.go | 16 ++++++++++++++++ templates/user/active.tmpl | 22 ++++++++++++++++++++++ web.go | 1 + 5 files changed, 60 insertions(+) create mode 100644 templates/user/active.tmpl diff --git a/modules/auth/mail.go b/modules/auth/mail.go index cdfcce4f9..3de18b677 100644 --- a/modules/auth/mail.go +++ b/modules/auth/mail.go @@ -39,3 +39,20 @@ func SendRegisterMail(user *models.User) { // async send mail mailer.SendAsync(msg) } + +// Send email verify active email. +func SendActiveMail(user *models.User) { + code := CreateUserActiveCode(user, nil) + + subject := "Verify your email address" + + data := mailer.GetMailTmplData(user) + data["Code"] = code + body := base.RenderTemplate("mail/auth/active_email.html", data) + + msg := mailer.NewMailMessage([]string{user.Email}, subject, body) + msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id) + + // async send mail + mailer.SendAsync(msg) +} diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index cf7bee4d2..33321d6e4 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -16,6 +16,10 @@ func SignInRequire(redirect bool) martini.Handler { ctx.Render.Redirect("/") } return + } else if !ctx.User.IsActive { + ctx.Data["Title"] = "Activate Your Account" + ctx.Render.HTML(200, "user/active", ctx.Data) + return } } } diff --git a/routers/user/user.go b/routers/user/user.go index 2d6bcedce..d702f2b95 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -99,6 +99,7 @@ func SignIn(ctx *middleware.Context, form auth.LogInForm) { ctx.Session.Set("userId", user.Id) ctx.Session.Set("userName", user.Name) + ctx.Render.Redirect("/") } @@ -223,3 +224,18 @@ func Pulls(ctx *middleware.Context) { func Stars(ctx *middleware.Context) { ctx.Render.HTML(200, "user/stars", ctx.Data) } + +func Activate(ctx *middleware.Context) { + code := ctx.Query("code") + if len(code) == 0 { + ctx.Data["IsActivatePage"] = true + // Resend confirmation e-mail. + if base.Service.RegisterEmailConfirm { + auth.SendRegisterMail(ctx.User) + } else { + ctx.Data["ServiceNotEnabled"] = true + } + ctx.Render.HTML(200, "user/active", ctx.Data) + return + } +} diff --git a/templates/user/active.tmpl b/templates/user/active.tmpl new file mode 100644 index 000000000..758516d77 --- /dev/null +++ b/templates/user/active.tmpl @@ -0,0 +1,22 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+
+

Active Your Account

+ {{if .IsActivatePage}} + {{if .ServiceNotEnabled}} +

Sorry, Register Mail Confirmation has been disabled.

+ {{else}} +

New confirmation e-mail has been sent to {{.SignedUser.Email}}, please check your inbox within 3 days.

+ {{end}} + {{else}} +

Hi, {{.SignedUser.Name}}, you have an unconfirmed email address({{.SignedUser.Email}}). If you haven't received a confirmation e-mail or need to resend a new one, please click botton below.

+
+
+ +
+
+ {{end}} +
+
+{{template "base/footer" .}} \ No newline at end of file diff --git a/web.go b/web.go index 97cfdcc43..e519fe104 100644 --- a/web.go +++ b/web.go @@ -84,6 +84,7 @@ func runWeb(*cli.Context) { m.Any("/user/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) m.Any("/user/delete", reqSignIn, user.Delete) m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) + m.Get("/user/activate", user.Activate) m.Any("/user/setting", reqSignIn, binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) m.Any("/user/setting/password", reqSignIn, binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword)