Mulpitle logins

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 19, 2010   (RSS)

By pgplast - July 19, 2010

I'm rather new to php (having come over from the dark world of windows and asp). (I have licensed CMS builder for a website I'm currently doing, and it is great!)

I have a question about the application of the CMS builder and Membership plugin for another project, however.

Would it be difficult to create a cms builder project that does the following?

1. Create a form for a registered user to use to store online info about himself.

2. Allow the form to contain a field the user employs to create and store a second password for the use of others

3. Allow someone else given the second password to log in the see the information but make no changes.

Thanks

Re: [pgplast] Mulpitle logins

By Chris - July 19, 2010

Hi pgplast,

For 1 and 2 you can simply add some extra fields and set up a "profile" page (there's a sample profile page included with the Membership plugin.)

Depending on your definition of "log in," 3 could be very simple or fairly difficult. The easiest solution would be to have a password form protecting your user_account detail viewer with some simple PHP code to make sure the visitor has supplied the correct "visitor password" before displaying the profile.

It might look something like this:

list($accountRecords,) = getRecords(array(
'tableName' => 'accounts',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$accountRecord = @$accountRecords[0]; // get first record

if (!$accountRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

$passwordSupplied = @$_REQUEST['visitor_password'];
$passwordSuccess = (@$_REQUEST['visitor_password'] == $accountRecord['visitor_password']);
?>

<?php if ($passwordSupplied && !$passwordSuccess): ?>
<p style="color: red;">Password incorrect! Please try again.</p>
<?php endif ?>

<?php if (!$passwordSuccess): ?>
<form action="?<?php echo http_build_query($REQUEST) ?>">
<input type="password" name="visitor_password" />
<input type="submit" />
</form>
<?php exit ?>
<?php endif ?>

<p>Thank you for supplying the correct password. Here's the information:</p>

<p>Field1: <?php echo htmlspecialschars($accountRecord['field1']) ?></p>
<p>Field2: <?php echo htmlspecialschars($accountRecord['field2']) ?></p>
<p>Field3: <?php echo htmlspecialschars($accountRecord['field3']) ?></p>
etc.


I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [pgplast] Mulpitle logins

By Chris - July 19, 2010

Hi pgplast,

For simplicity, I was thinking you could have separate viewers, but it wouldn't be too hard to add an extra check to that viewer to see if the record belongs to the user who's currently logged in.

I'd recommend setting this up with separate viewers first, just to keep everything simple and the site structure easy to change, then combining viewers at the end when you have everything working the way you want.
All the best,
Chris

Re: [chris] Mulpitle logins

By pgplast - July 19, 2010

Thanks, Chris.