MonkeyCMS Forum

Go Back   MonkeyCMS Forum > MonkeyCMS > Installation and Configuration Discussion
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 05-17-2009, 04:06 PM
chrisjlocke chrisjlocke is offline
Super Moderator
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 1,052
Default Tutorial: Adding the login engine into MonkeyCMS

When you create a new skin, its a simple process of creating some additional forms to allow users to register, and restrict content to specific groups of users.

The first part is creating a login box somewhere on your site. This is a simple form.

PHP Code:
<form method="post" action="login.php" name="login">
<
p>
<
label for="username">Username</label>
<
input id="username" type="text" maxlength="50" value="" name="username"/>
</
p>

<
p>
<
label for="password">Password</label>
<
input id="password" type="password" value="" maxlength="50" name="password"/>
</
p>

<
p><input type="submit" value="Login"/></p>
</
form
The login process needs some message templates, so create Error:GenericMessage and GenericMessage as message fixed templates.

PHP Code:
<h1>
[
message_title]
</
h1>

<
p>
[
message]
</
p
You'll need a link to register.php, which allows users to register on your site. This will also need a page fixed template called Register. Although just another form, its also handy to include some email validation JavaScript.

PHP Code:
<script>
function 
isValidEmail(str) **
   return (
str.indexOf(".") > 2) && (str.indexOf("@") > 0);
**
 
function 
validateForm() **
if ((!
isValidEmail(document.registerform.reg_email.value) || 

!
isValidEmail(document.registerform.reg_email2.value))) **
alert("The email address you entered is invalid");
** else if (
document.registerform.reg_email.value != 

document.registerform.reg_email2.value) **
alert("The email addresses you entered do not match");
** else **
document.registerform.submit();
**
**
</script>

<form name="registerform" action="register.php" method="post">

<label for="reg_user_name">Username</label>
<input type="text" name="reg_user_name" id="reg_user_name" >

<label for="reg_password">Password</label>
<input type="password" name="reg_password" id="reg_password" >

<label for="reg_password2">Confirm Password</label>
<input type="password" name="reg_password2" id="reg_password2" >

<label for="reg_email">Your Email</label>
<input type="text" name="reg_email" id="reg_email" >

<label for="reg_email2">Confirm Email</label>
<input type="text" name="reg_email2" id="reg_email2" >

<label for="dob_day">Date of Birth</label>
<table>
<tr>
<td><font size=-2>Day</font></td>
<td><font size=-2>Month</font></td>
<td><font size=-2>Year</font></td>
</tr>

<tr>
<td>
<select name="dob_day" class="text" style="width:60px;">
%% global $strHTMLOutput; $i = 0; while ($i < 31) ** $i++; 
$strHTMLOutput=$strHTMLOutput."<option value=$i>$i</option>";  ** %%
</select>
</td>
<td>
<select name="dob_month" class="text" style="width:60px;">
%% global $strHTMLOutput; $i = 0; while ($i < 12) ** $i++; 
$strHTMLOutput=$strHTMLOutput."<option value=$i>$i</option>";  ** %%
</select>
</td>
<td>
<select name="dob_year" class="text" style="width:60px;">
%% global $strHTMLOutput; $i = date("Y"); while ($i > 1899) ** $i--; 
$strHTMLOutput=$strHTMLOutput."<option value=$i>$i</option>";  ** %%
</select>
</td>
</tr>
</table>

<label for="mailinglist">Join Mailing List:</label>
<select name="mailinglist" id="mailinglist" >
<option value=1>Yes</option>
<option value=0>No</option>
</select>

<input class="submit" type=button onclick="validateForm()" value="Register"> 
Finally, you'll need a page template for users who've forgotten their password. This should be called ForgottenPassword.

PHP Code:
<form action="forgottenpassword.php" method="post">
<
p>Please enter one of the following and we will send you a new password.</p>

<
p>
<
label for="email">Email</label>
<
input type="text" name="email">
</
p>

<
p>or</p>

<
p>                              
<
label for="username">Username</label>
<
input type="text" name="username">
</
p>

<
p>
<
input type="submit" value="Reset Password" >
</
p>

</
form
__________________
http://www.cscomputerservices.co.uk/ | Providing complete computer solutions | Web hosting with MonkeyCMS pre-installed

Last edited by chrisjlocke : 05-17-2009 at 04:18 PM.
Reply With Quote
  #2  
Old 06-19-2009, 03:00 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 450
Default

This has been really useful, thanks Chris.

How do you set where a user ends up once logged in? At the moment if I log in from my custom Skin, once logged in I end up at the Default page but using the Default skin.
Reply With Quote
  #3  
Old 06-19-2009, 03:18 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 450
Default

Found the answer in another post:

http://www.monkeycms.com/forum/showp...52&postcount=1

I was looking to have a section for registered users which will have a different colour scheme and extra content. Will I have overwrite the templates in the Default skin, or can I specify the skin which registered users will use?
Reply With Quote
  #4  
Old 06-20-2009, 11:16 AM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,593
Default

You can disable the Default skin and then it won't be selected in the user settings. I can also look at adding a setting to change the registered users default skin if you want for the next release.
Reply With Quote
  #5  
Old 06-21-2009, 06:55 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 450
Default

If its easily do-able then I think I might be quite useful Colin
Reply With Quote
  #6  
Old 06-21-2009, 06:57 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,593
Default

I will try and get something done next week

Might be a struggle though as I've got to do my accounts too as the accountant is now pestering me loads
Reply With Quote
  #7  
Old 06-23-2009, 10:49 AM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,593
Default

This is now into 1.5.0-3 which I'll try and release in the next 48 hours
Reply With Quote
  #8  
Old 06-23-2009, 01:31 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 450
Default

Looking forward to the new release Colin!

Is there any way of dictating which page a user is taken to when they log in or log out?
Reply With Quote
  #9  
Old 06-23-2009, 01:34 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,593
Default

Quote:
Originally Posted by harvey View Post
Looking forward to the new release Colin!

Is there any way of dictating which page a user is taken to when they log in or log out?
Not as yet, but I can add that option.

That said, I need to look at the logout process as there are issues with it - so I'll be doing that shortly.
Reply With Quote
  #10  
Old 06-23-2009, 03:16 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,593
Default

Quote:
Originally Posted by Colin View Post
Not as yet, but I can add that option.

That said, I need to look at the logout process as there are issues with it - so I'll be doing that shortly.
Added the option to override the URL of the login and logout process

Just enter the alternative URLs in the Login Options section of the site settings in 1.5.0-3 +
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT. The time now is 07:16 AM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© Poisonous Monkey