Skip to content
Snippets Groups Projects
Commit 995e73c3 authored by Anton Bagliy's avatar Anton Bagliy
Browse files

ADD: log_sigin_detailed table with openid parameters and error messages #347

parent 0bbcc7af
Branches
Tags
No related merge requests found
CREATE SEQUENCE seq_logs_signin_detailed
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE logs_signin_detailed (
id integer DEFAULT nextval('seq_logs_signin_detailed'::regclass) NOT NULL,
accountid integer,
globalkey character varying NOT NULL,
isstudent integer,
isstaff integer,
error_message character varying,
date timestamp(0) without time zone DEFAULT now() NOT NULL
);
CREATE INDEX key_logs_signin_detailed ON logs_signin_detailed USING btree (globalkey);
ALTER TABLE ONLY logs_signin_detailed
ADD CONSTRAINT logs_signin_detailed_pkey PRIMARY KEY (id);
CREATE OR REPLACE FUNCTION public.log_sigindetailed(paccountid integer, pisstaff integer, pisstudent integer, pglobalkey character varying, pmessage character varying)
RETURNS integer
LANGUAGE plpgsql
AS $function$
begin
INSERT INTO logs_signin_detailed (AccountID, GlobalKey, IsStudent, IsStaff, error_message) VALUES (paccountid, pglobalkey, pisstudent, pisstaff, pmessage);
RETURN 0;
END
$function$;
......@@ -114,6 +114,7 @@ class Controller_Handler_Sign extends Controller_Handler
$email = $_GET["openid_sreg_email"];
$id = 0;
$error = null;
try {
if ($isStudent) {
$globalKey = 'st-' . str_pad(str_replace('st-', '', $globalKey), 9, '0', STR_PAD_LEFT);
......@@ -122,7 +123,9 @@ class Controller_Handler_Sign extends Controller_Handler
$id = User::instance()->signInByOpenID($globalKey);
}
} catch (Exception $e) {
$error = $e->getMessage();
} finally {
Model_Logs::logSigninDetailed($id, $isStaff, $isStudent, $globalKey, $error);
}
if ($id <= 0) {
......
......@@ -28,4 +28,17 @@ class Model_Logs extends Model
return $result;
}
public static function logSigninDetailed($accountID, $isStaff, $isStudent, $globalKey, $errorMessage) {
$query = 'SELECT * FROM log_sigindetailed(:account, :isstaff, :isstudent, :globalkey, :errormessage)';
$result = DB::query(Database::UPDATE, $query)
->param(':account', $accountID)
->param(':isstaff', $isStaff)
->param(':isstudent', $isStudent)
->param(':globalkey', $globalKey)
->param(':errormessage', $errorMessage)
->execute();
return $result;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment