This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

custom login page

In UserSpice 4.3 and Below · Started by roger on 2018-06-21 12:39 pm · 19730 views · 6 replies

Hi!
...I'm a noob. but the installation was easy and userspice is running of course. Everything works. What I would like to do, is create a custom user page for each user. They don't really differentiate much, but I would need to transfer a variable (username) to a form respectively when the form is submitted the username automatically in there.

This is how the form works right now:
====
<form class="form-horizontal" role="form" id="test-form">
<div class="form-group">
<label class="col-lg-3 control-label">First Name</label>
<div class="col-lg-3 inputGroupContainer">
<div class="input-group">
<input type="text" class="form-control" name="firstName" placeholder="First Name"/>
</div>
</div>
</div>
====


So ideally I have a hidden form field that gets the username or full name through the login procedure. I can then submit the form without the user having to input anything.

Any help is greatly appreceated.
R.
So if the user is logged in, you already have access to the user's username in the variable $user->data()->username;

If you want them to physically go to a different page, you can do that in usersc/scripts/custom_login_script

I guess the question is what do you want to do with the page?
well, after logging in they should see a page (or section for that matter) with a form. On submit each individual user should have their username / name submitted.
Ok, so I think you're thinking about that wrong. Once someone is logged in, you have the entire user object at your disposal. In fact, try this...

Go on a page where the user is logged in. Any page and add this code...
<?php
if(isset($user) && $user->isLoggedIn()){
dump($user);
}
?>

You don't need that isset part, but what it does is stops the page from throwing a bunch of errors if the user isn't logged in.

So, once you have all that information, you can just call it by doing
$user->data()->fname
or
$user->data()->email
and that will always give you that information of the logged in user.

So on submit, you would just do
if(!empty($_POST){
$username = $user->data()->username;
}
Thanks, Mudmin

I added the lines in the account.php - which essentially has the user information since after login.
this one

<?php
if(isset($user) && $user->isLoggedIn()){
dump($user);
}
?>

didn't render the site correctly.
this snippet: $user->data()->fname - seems to be working fine (no render errors)
and this one:

if(!empty($_POST){
$username = $user->data()->username;
}

I don't know how to work :/ sorry
got it work like this: <input type="text" class="form-control" name="user" value="<?=echouser($user->data()->id)?>"/>
Yes. That works. The thing you risk is that someone could change it. If it were me, I would try 2 more things.

I would add the word readonly to the end of the input
<input type="text" name="user" value="<?=$user->data()->id?>" readonly>

but then, to be honest, if on form submission I would not even look at what's inputted on the form input. I would just do
$username = $user->data()->username;

Unless you really want them to be able to put something other than their username in there, because even with readonly, they could post a different username (like admin).