#1 2017-09-22 13:00:31

Desenvolvimento
Member
Registered: 2017-09-14
Posts: 6

30 - MVC - is it possible to check the session when a view is called?

Hello, according to example 30 - MVC ..., is it possible to check the session when a view is called? Example: when calling the "/ root / blog / dashboard" view, if the session does not exist, redirect to "/ root / blog / login".

Tks

Offline

#2 2017-09-22 13:44:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,232
Website

Re: 30 - MVC - is it possible to check the session when a view is called?

Yes, raise a MVC exception with a goto redirection if there is no cookie session.

See for instance in sample 30:

procedure TBlogApplication.ArticleEdit(var ID: TID;
  const Title,Content: RawUTF8; const ValidationError: variant;
  out Article: TSQLArticle);
var AuthorID: PtrUInt;
begin
  AuthorID := GetLoggedAuthorID(canPost,Article);
  if AuthorID=0 then
    raise EMVCApplication.CreateGotoError(sErrorNeedValidAuthorSession);
  ...

Offline

#3 2017-09-22 15:35:49

Desenvolvimento
Member
Registered: 2017-09-14
Posts: 6

Re: 30 - MVC - is it possible to check the session when a view is called?

Thank you!

Offline

Board footer

Powered by FluxBB