# Storing data for users

**URL:** <https://community.dreamfactory.com/t/storing-data-for-users/2915>\
**Category:** Users & Roles\
**Created:** [June 30, 2016, 2:39pm UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915 "2016-06-30T14:39:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gudmundur\_Stefansson](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Gudmundur\_Stefansson](https://community.dreamfactory.com/u/Gudmundur_Stefansson)\
**Post date:** [June 30, 2016, 2:39pm UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/1 "2016-06-30T14:39:48Z")

</div>

I am working on a project connecting to a MySQL database. I want the users to be allowed to only access records that are connected to them via SSN. To do this, I would need to store each user’s SSN when they register, preferrably as a lookup key.

I know how to force the user to provide an SSN when they call the user/register method, but how can I store it?

---

<div class="post-metadata">

**Author:** ![delebash](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@delebash](https://community.dreamfactory.com/u/delebash)\
**Post date:** [July 1, 2016, 5:28am UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/2 "2016-07-01T05:28:13Z")

</div>

What about calling a stored procedure and then limiting a role to stored procs.

See S[ql wiki stored proc](https://wiki.dreamfactory.com/DreamFactory/Features/Database/SQL#Listing_Available_Stored_Procedures_or_Functions)s

So just make a get stored proc gUserSsn where username is a parameter that pulls the ssn from your lookup table and restricts your data

Same for add cUserSsn which creates a new ssn user relationship in your lookup table

The use the scripts tab to fire the stored procedures during registration  
Or maybe use the scripts tab for everything.

---

<div class="post-metadata">

**Author:** ![delebash](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@delebash](https://community.dreamfactory.com/u/delebash)\
**Post date:** [July 1, 2016, 5:41am UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/3 "2016-07-01T05:41:02Z")

</div>

You might try scripts tab then process events/users/register

You could also call a custom stored procedure that gets fired when they register adding the username/ssn to a lookup table and then a get stored proc in you api that pulls the snn out of the lookup table so you can restrict data on further api calls

---

<div class="post-metadata">

**Author:** ![Gudmundur\_Stefansson](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Gudmundur\_Stefansson](https://community.dreamfactory.com/u/Gudmundur_Stefansson)\
**Post date:** [July 1, 2016, 11:55am UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/4 "2016-07-01T11:55:11Z")

</div>

Limiting the role to stored procedures sounds like it kinda defeats the purpose of using dreamfactory. The main reason for using it is to get the REST API.

So far I’ve tried to create a table, mapping [user.id](http://user.id) to SSN, and populating the table on user.register.post.post\_process. I managed to write the SSN to the table, but not the [user.id](http://user.id).

Another thing that I tried, which would make things a lot simpler if I got it to work, was to create a lookup key for the user on user.register.post.post\_process. I tried doing it according to [this](https://community.dreamfactory.com/t/lookup-key-value-in-database/1157/4), but it didn’t work.

Both approaches would work if I could get/set lookup keys for users via scripting, but I still haven’t found a way to do that.

---

<div class="post-metadata">

**Author:** ![Gudmundur\_Stefansson](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Gudmundur\_Stefansson](https://community.dreamfactory.com/u/Gudmundur_Stefansson)\
**Post date:** [July 1, 2016, 1:59pm UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/5 "2016-07-01T13:59:55Z")

</div>

I figured out a way to do this. I added a script to user.register.post.post\_process, and stored the SSN using user/custom, like so:

`
var ssn = event.request.payload.ssn;
var emailString = “email%3D’” + event.request.payload.email + “’”;
var pathString = “system/user?fields=id&filter=” + emailString;
var result = platform.api.get(pathString, {});
if (result.content.resource && result.content.resource.length === 1) {
var user_id = result.content.resource[0].id;
var user_data = {
“resource”: [
{
“user_id”: user_id,
“name”: “ssn”,
“value”: ssn
}
]
};
```
platform.api.post("user/custom", user_data);

```
}
`

And then I can retrieve this value for the logged-in user by making a GET request to ‘user/custom’

---

<div class="post-metadata">

**Author:** ![DFCommunityManager](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/dfcommunitymanager/32/887_2.png) [@DFCommunityManager](https://community.dreamfactory.com/u/DFCommunityManager)\
**Post date:** [July 8, 2016, 5:50pm UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/6 "2016-07-08T17:50:21Z")

</div>

Hey @Gudmundur_Stefansson,

Thanks for posting your answer and updating the thread! Glad to hear that you figured it out.

Thanks,  
@AlexBowen

---

<div class="post-metadata">

**Author:** ![Gudmundur\_Stefansson](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@Gudmundur\_Stefansson](https://community.dreamfactory.com/u/Gudmundur_Stefansson)\
**Post date:** [August 3, 2016, 11:02am UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/7 "2016-08-03T11:02:44Z")

</div>

I figured out a better way to do this.  
In user.register.post.post\_process:

```
var ssn = event.request.payload.ssn;
var user_id = platform.session.user.id;

platform.api.patch("system/user?related%3Duser_lookup_by_user_id", {
    "resource": [
        {
            "id": user_id,
            "user_lookup_by_user_id": [
                {
                    "name": "ssn",
                    "value": ssn,
                    "private": false,
                    "description": "The SSN of the user."
                }
            ]
        }
    ]
});

```

The above code sets a lookup key for the newly registered user.

---

<div class="post-metadata">

**Author:** ![DFCommunityManager](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/dfcommunitymanager/32/887_2.png) [@DFCommunityManager](https://community.dreamfactory.com/u/DFCommunityManager)\
**Post date:** [August 4, 2016, 1:57pm UTC](https://community.dreamfactory.com/t/storing-data-for-users/2915/8 "2016-08-04T13:57:29Z")

</div>

This is great @Gudmundur_Stefansson.

Thanks!
