#1 2018-01-13 08:30:05

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Force use to login on MVC/MVVM Web application

I'm trying to implement the Controller of MVC/MVVM Web application (MVCViewModel) as indicated on paragraph 19.2 of documentation but I have a problem.
The Default method is always accessible to the user.

In my case I'd like to force the use to login so I want check CurrentSession to check cookies status and show login page if the user has not logged in. In alternative, if the user is logged he will see the INDEX page of Web applications (this can be Default or other view).

My problem is: I cannot avoid to use Defualt method as main page of my application but I cannot understand how how can redirect the user on login page if CurrentSession  test is to passed.

I have to use GotoView method? This method ask my a TMVCAction.

Offline

#2 2018-01-13 14:25:36

Chaa
Member
Registered: 2011-03-26
Posts: 245

Re: Force use to login on MVC/MVVM Web application

You can use code like this:

procedure TMyApp.Default(var Scope: Variant);
begin
    if CurrentSession.CheckAndRetrieve(...) <> 0 then
    begin
        // OK, user logged in
    end
    else
        // Redirect to Login page
        raise EMVCApplication.CreateGotoView('Login', [], HTTP_TEMPORARYREDIRECT);
end;

Offline

Board footer

Powered by FluxBB