@@ -1005,11 +1005,15 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
1005
1005
Action : database .AuditActionLogin ,
1006
1006
})
1007
1007
)
1008
+ aReq .Old = database.APIKey {}
1008
1009
1009
1010
defer commitAudit ()
1010
1011
1011
1012
var loginWithPassword codersdk.LoginWithPasswordRequest
1012
1013
if ! httpapi .Read (ctx , rw , r , & loginWithPassword ) {
1014
+ // We pass a disposable user ID just to force an audit diff
1015
+ // and generate a log for a failed login
1016
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1013
1017
return
1014
1018
}
1015
1019
@@ -1020,15 +1024,23 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
1020
1024
httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
1021
1025
Message : "Internal error." ,
1022
1026
})
1027
+ // We pass a disposable user ID just to force an audit diff
1028
+ // and generate a log for a failed login
1029
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1023
1030
return
1024
1031
}
1025
1032
1033
+ aReq .UserId = user .ID
1034
+
1026
1035
// If the user doesn't exist, it will be a default struct.
1027
1036
equal , err := userpassword .Compare (string (user .HashedPassword ), loginWithPassword .Password )
1028
1037
if err != nil {
1029
1038
httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
1030
1039
Message : "Internal error." ,
1031
1040
})
1041
+ // We pass a disposable user ID just to force an audit diff
1042
+ // and generate a log for a failed login
1043
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1032
1044
return
1033
1045
}
1034
1046
if ! equal {
@@ -1037,13 +1049,19 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
1037
1049
httpapi .Write (ctx , rw , http .StatusUnauthorized , codersdk.Response {
1038
1050
Message : "Incorrect email or password." ,
1039
1051
})
1052
+ // We pass a disposable user ID just to force an audit diff
1053
+ // and generate a log for a failed login
1054
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1040
1055
return
1041
1056
}
1042
1057
1043
1058
if user .LoginType != database .LoginTypePassword {
1044
1059
httpapi .Write (ctx , rw , http .StatusForbidden , codersdk.Response {
1045
1060
Message : fmt .Sprintf ("Incorrect login type, attempting to use %q but user is of login type %q" , database .LoginTypePassword , user .LoginType ),
1046
1061
})
1062
+ // We pass a disposable user ID just to force an audit diff
1063
+ // and generate a log for a failed login
1064
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1047
1065
return
1048
1066
}
1049
1067
@@ -1052,6 +1070,9 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
1052
1070
httpapi .Write (ctx , rw , http .StatusUnauthorized , codersdk.Response {
1053
1071
Message : "Your account is suspended. Contact an admin to reactivate your account." ,
1054
1072
})
1073
+ // We pass a disposable user ID just to force an audit diff
1074
+ // and generate a log for a failed login
1075
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1055
1076
return
1056
1077
}
1057
1078
@@ -1065,10 +1086,12 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
1065
1086
Message : "Failed to create API key." ,
1066
1087
Detail : err .Error (),
1067
1088
})
1089
+ // We pass a disposable user ID just to force an audit diff
1090
+ // and generate a log for a failed login
1091
+ aReq .New = database.APIKey {UserID : uuid .New ()}
1068
1092
return
1069
1093
}
1070
1094
1071
- // key := httpmw.APIKey(r)
1072
1095
aReq .New = * key
1073
1096
1074
1097
http .SetCookie (rw , cookie )
0 commit comments