From b7e5e58e5a0aabdeb2fde69a712134b9af2b002b Mon Sep 17 00:00:00 2001
From: Jason Song <i@wolfogre.com>
Date: Thu, 10 Nov 2022 00:42:06 +0800
Subject: [PATCH] Set last login when activating account (#21731)

Fix #21698.

Set the last login time to the current time when activating the user
successfully.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
---
 routers/web/auth/auth.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go
index 25d70d7c47818..0f8128946c940 100644
--- a/routers/web/auth/auth.go
+++ b/routers/web/auth/auth.go
@@ -783,6 +783,13 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) {
 		return
 	}
 
+	// Register last login
+	user.SetLastLogin()
+	if err := user_model.UpdateUserCols(ctx, user, "last_login_unix"); err != nil {
+		ctx.ServerError("UpdateUserCols", err)
+		return
+	}
+
 	ctx.Flash.Success(ctx.Tr("auth.account_activated"))
 	ctx.Redirect(setting.AppSubURL + "/")
 }