#1 2013-12-22 08:04:14

foncci
Member
Registered: 2013-11-15
Posts: 53

Change Password

Hi, I'm trying to change a password of the current user using a Interface based service.

function TServiceSQLExec.ChangePassword(aPass : RawUTF8) : RawJSON;
var
  Ctxt : TServiceRunningContext;
  AuthUser : TSQLAuthUser;
  Rest : TSQLRestServerFullMemory;
begin
  Ctxt := CurrentServiceContext;
  Rest := Ctxt.Request.Server as TSQLRestServerFullMemory;
  AuthUser := Rest.SessionGetUser(Ctxt.Request.Session);
  AuthUser.PasswordPlain := aPass;
  Rest.Update(AuthUser);
  Rest.UpdateToFile;
end;

It saves the password OK but it saves the GroupRights field equal to 0 instead of 3. I'm using TSQLRestServerFullMemory and a JSON file for user registration like sample 16.
What am I doing wrong?

Thanks in advance,

Al

Offline

#2 2013-12-22 08:17:53

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

Re: Change Password

As stated by the doc, SessionGetUser() does not retrieve the full User() content, but makes a copy of the value in memory.

Solution is not to use this SessionGetUser() method to retrieve the member, but load AuthUser from the ORM via AuthUser.Create(Rest,ID).

Offline

#3 2013-12-27 06:56:55

foncci
Member
Registered: 2013-11-15
Posts: 53

Re: Change Password

Hi ab, first of all Marry Christmas, second, it works perfect, thank you and third, when debugging the server I got this exception in case of time-out or if the client close the connection:

20131227 02492900 EXC   EHttpApiServer ("HttpSendHttpResponse failed: An operati
on was attempted on a nonexistent network connection (1229)") at 006C97D2  stack
trace 0045B1BD 00408B26 762A336A 77379F72 77379F45

I got 2 others access violations, it is very simple to reproduce, just start debugging and have a coffee or smoke a cigarette.

Thanks in advance and merry Christmas again.

Al

Offline

#4 2013-12-27 13:19:10

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

Re: Change Password

Now THttpApiServer won't try to send an error message when connection is broken.
See http://synopse.info/fossil/info/395b247710

Offline

#5 2013-12-28 15:32:45

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

Re: Change Password

Unfortunately, I still get these exceptions when stepping through my server code and it doesn't take more than 10, 15 secs to have the exception raised.
I downloaded a Nightly Build today.


fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...

Offline

#6 2013-12-28 16:36:10

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

Re: Change Password

The EHttpApiServer does make sense - and it is catched and the server continue to run - so it is safe to have it.

What are the access violations you are talking about?

Offline

#7 2013-12-29 05:41:08

foncci
Member
Registered: 2013-11-15
Posts: 53

Re: Change Password

Hi ab, a regular access violation, I can send you a print screen if you want but it is a "pretty regular" access violation. By the way, what is the best place to catch EHttpApiServer exception? It is raised after the method is completed.

Regards,

AL

Offline

#8 2013-12-29 16:20:46

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

Re: Change Password

Please enable logging, and detailed map file in project options, then provide the stack trace.

AFAIR EHttpApiServer is already catched.

Offline

#9 2013-12-31 07:19:52

foncci
Member
Registered: 2013-11-15
Posts: 53

Re: Change Password

Hi, logging is enabled and verbose and .map file or {$D+} is active but no stack is returned in the log because the Access Violation is raised inside procedure AddStackManual(Stack: PPtrUInt); ( Of course if you disable logging no Access Violation is raised )
in line
      while (PtrUInt(stack)<max_stack) do begin
        st := stack^;
        if ((st>max_stack) or (st<min_stack)) and <------ Exception is here
           not IsBadReadPtr(pointer(st-8),12) and
           ((pByte(st-5)^=$E8) or check2(st)) then begin
          TSynMapFile.Log(fWriter,st); // will ignore any TSynLog.* methods
          dec(depth);
          if depth=0 then break;
        end;
        inc(stack);
      end;
    except
      // just ignore any access violation here
    end;

The console LOG is:
20131231 03130315 srvr          TSQLRestServerFullMemory(0575B170) POST MySQLExe
c.ChangePassword -> 200
20131231 03130315  -    TSQLRestServerFullMemory(0575B170). 77.034.233
20131231 03141752 EXC   EHttpApiServer ("HttpSendHttpResponse failed: An operati
on was attempted on a nonexistent network connection (1229)") at 007DE63E  stack
trace 00475925 00408E72 00639D4C 00528E99 7564336A 774A9F72 774A9F45

Last edited by foncci (2013-12-31 07:57:52)

Offline

#10 2013-12-31 08:05:08

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

Re: Change Password

The stack trace is there: see the list of hexa values.
The av is catched, so can be ignored.
But your map file is not detailed so you do not have line numbers.

Everything sounds OK to me here.

Offline

Board footer

Powered by FluxBB