# Login with custom UserInfo in client (code-first)

**URL:** https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747
**Category:** Remoting SDK
**Tags:** delphi
**Created:** [August 4, 2020, 8:00am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747 "2020-08-04T08:00:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![claudio.piffer](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@claudio.piffer](https://talk.remobjects.com/u/claudio.piffer)
#### Post date: [August 4, 2020, 8:00am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747/1 "2020-08-04T08:00:37Z")

</div>

Hi

I have a problem whose I don’t understand cause.

I defined a login service (code-first) with a custom UserInfo class that I send to client when the login is successful.

```
var
  LUserInfoEx: TUserInfoEx;
begin
  LUserInfoEx := ValidateUser(AUserID, APassword);

  ALoginSuccessful := Assigned(LUserInfoEx); // AUserID = APassword;

  if ALoginSuccessful then
  begin
    LoadWardsUser(LUserInfoEx.PKUser, LUserInfoEx.Wards);

    AUserInfo := LUserInfoEx; 
    AUserInfo.SessionID := GuidToString(ClientID);
    AUserInfo.UserID := AUserID;

    Session['UserID'] := AUserID;
    Session['PKUser'] := LUserInfoEx.PKUser;
    try
      LoginUser(LUserInfoEx.PKUser, FClientAddess);
    except
      // DestroySession;
      LogoutUser;
      raise;
    end;
  end
  else
  begin
    LogoutUser;
  end;

```

The function ValidateUser check the username and password and if ok create the TUserInfoEx class and load the all data.

```
  Result := TUserInfoEx.Create;
  Result.PKUser := LUserDataSet.FieldByName('Pkpersonale').AsInteger;
  Result.FirstName := LUserDataSet.FieldByName('Nome').AsString;
  Result.LastName := LUserDataSet.FieldByName('Cognome').AsString;
  Result.FiscalCode := LUserDataSet.FieldByName('CodiceFiscale').AsString;
  Result.IsAdmin := LUserDataSet.FieldByName('IsAdmin').AsInteger = 1;
  Result.IsSuperUser := LUserDataSet.FieldByName('Superuser').AsInteger = 1;
  Result.IsInternal := LUserDataSet.FieldByName('IsInternal').AsInteger = 1;
  Result.DatePasswordExpiration := LUserDataSet.FieldByName('ScadenzaPwd').AsDateTime;
  Result.DateLastChengedPassword := LUserDataSet.FieldByName('ModPassword').AsDateTime;
  Result.ChangePassword := (LUserDataSet.FieldByName('CambiaPwd').AsInteger = 1) or
    (LUserDataSet.FieldByName('ScadenzaPwd').AsDateTime > Now) or
    (LUserDataSet.FieldByName('ScadenzaPwd').AsDateTime = 0) or
    (IncDay(LUserDataSet.FieldByName('ModPassword').AsDateTime, LUserDataSet.FieldByName('ValiditaPwd').AsInteger) > Now);
  Result.ResetPassword := LUserDataSet.FieldByName('ResetPswd').AsInteger = 1;
  Result.Email := LUserDataSet.FieldByName('Email').AsString;
  Result.RequiredPIN := LUserDataSet.FieldByName('RichiediPin').AsInteger = 1;
  Result.RegistrationNumber := LUserDataSet.FieldByName('Matricola').AsString;
  Result.VocalProfile := LUserDataSet.FieldByName('ProfiloVocale').AsString;
  Result.AllowOverbooking := LUserDataSet.FieldByName('AllowOverbooking').AsInteger = 1;
  Result.SelectedWardIndex := -1;

```

Server side work all!

In client side when i try to call the login method the generated unit \_int raise an exception when load the TUserInfoEx class.

 ![image](https://talk.remobjects.com/uploads/default/original/2X/c/cd49d447731bd5df6c3eca99f04031f683c45d52.png)

 ![image](https://talk.remobjects.com/uploads/default/original/2X/8/86a42e9baf4afe2386405678f1aadf3cf95de10d.png)

 ![image](https://talk.remobjects.com/uploads/default/original/2X/6/6c2cd38a7760a4c7b9283f3b8eb74287d4a6bbba.png)

This is the code into uROSerializer unit

 ![image](https://talk.remobjects.com/uploads/default/original/2X/7/74cef7cff822cef738c59fdc9d12d0944ac0d014.png)

and this teh procedure ReadUnicodeString into uROStreamSerializer

 ![image](https://talk.remobjects.com/uploads/default/original/2X/e/e3ed390e7fe9b5a6d6cca4358ce036d29ab969ed.png)

The problem is in the sze integer var. The value is : 1127301421. why is it so big?

The initial project was developed with rodl, while now I’m rewriting it in code-first (starting a new project), and I had never experienced this problem before.

Any help?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 4, 2020, 8:38am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747/2 "2020-08-04T08:38:37Z")

</div>

Hi,

> [@claudio.piffer](#):
>
> I defined a login service (code-first) with a custom UserInfo class that I send to client when the login is successful.

looks like some fields were serialized incorrectly.  
this may happen when non-standard RODL datatype like `Word`, `Byte`, etc are used.  
I need a testcase that reproduces this error.  
you can send it to support@ for keeping privacy

---

<div class="post-metadata">

### Author: ![claudio.piffer](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@claudio.piffer](https://talk.remobjects.com/u/claudio.piffer)
#### Post date: [August 4, 2020, 9:31am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747/3 "2020-08-04T09:31:26Z")

</div>

Hi EvgenyK

it’s not easy but I create it and send it to you by email

Many thanks

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 4, 2020, 9:37am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747/4 "2020-08-04T09:37:01Z")

</div>

Hi,

just create a server method that returns your struct that causes failure on client-side.  
it will be easier than creating a full functionality DA Server …

---

<div class="post-metadata">

### Author: ![claudio.piffer](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@claudio.piffer](https://talk.remobjects.com/u/claudio.piffer)
#### Post date: [August 4, 2020, 10:23am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747/5 "2020-08-04T10:23:57Z")

</div>

Hi EvegnyK

I created the sample by my real project and removed all code that access to DB.

I send email to support@ …

Many thanks!!

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 4, 2020, 11:25am UTC](https://talk.remobjects.com/t/login-with-custom-userinfo-in-client-code-first/22747/6 "2020-08-04T11:25:48Z")

</div>

Hi,

your issue - you have used class declared in RODL as ancestor and didn’t override `ReadComplex`&`WriteComplex` methods, i.e. rules how to serialize/deserialize data.  
as a result, your class used rules from `UserInfo` that only reads/writes 5 fields declared in `UserInfo`.

workaround: return original behavior of `TROComplexType`, i.e.

```auto
procedure TUserInfoEx.ReadComplex(aSerializer: TObject);
begin
  ReadObjectFromSerializer(TROSerializer(ASerializer),Self);
end;

procedure TUserInfoEx.WriteComplex(aSerializer: TObject);
begin
  WriteObjectToSerializer(TROSerializer(ASerializer),Self);
end;

```
