Jump to content

Advanced User Module?


Lars282
 Share

Recommended Posts

Hey!

First, and off topic, I am really impressed by the form builder module. I am have a website coming up that will require a lot of advanced forms and I will certainly give it a try!

Now ... I was wondering whether there are some modules out there that allow more user interaction? I need user profiles, private messaging, email notification settings, etc ... is there anything?

Also, I would need users to be able to 'subscribe' to comments threads ... ie if they have posted a comment on a page, they should receive notifications for future comments but be able to unsubscribe?

Thanks,

Lars

Link to comment
Share on other sites

I don't think there are modules for those, but for user profiles you can do by adding fields to the "user" template (see the blog profile); For private messages you would need a page fieldType for choosing receiver and a text field, then, you could have a message center for each user with

$msgsForMe = $pages->find("template=privateMsg, receiver=$user");

Settings is easy, a simple page with everything you need as fields (see the homepage of the blogprofile); email notifications... well, that depends of what you want to notify, of course, but I can imagine that you would have to make a module that hooks on the page saving (in the case of notifications for private messages, for sure), and to mess around with mail() or something more robust.

But overall, everything is possible depending on the time you want to dedicate to it :)

  • Like 1
Link to comment
Share on other sites

Just expanding a little on one aspect of diogo's post in case some newer folks don't yet know how to get to the User template or how to expand the fields shown in the user's profile.

To add new fields to the User template...

  1. Navigate to the templates page
  2. Click open the "Filters"
  3. Click open "Show System Templates" and click "Yes"

You should now be able to edit the User template. Once you have added your fields to the template & want them to appear in the user's profile page...

  1. Navigate to the Modules page
  2. Find the "User Profile" module and click it open
  3. Choose all the applicable fields from the list and save the settings.
  • Like 4
Link to comment
Share on other sites

I'm just about to add some more functionality to a private tutor website.

I would like to be able for each student to be able to download certain files.

Any thoughts on whether it would be better to expand the user profile (with a files field) or to add a new page with subpages for each student.

Are there any differences at all? Would I be able to display more information further down the line as simply with "user" as with a normal page?

Thanks in advance guys

Link to comment
Share on other sites

Am trying with the user profiles. I am also trying to have a page where I list all students studying a particular subject. I've been trying to user roles for subjects but I'm having no joy with the following:

$students = $users->find("roles=geography-a-level");

Would roles not be a good fit for this purpose? Am I better using page references?

Thanks

Link to comment
Share on other sites

Users don't represent viewable pages on the front-end so you may want to connect them with some other template by way of URL segments. i.e.

$username = $sanitizer->pageName($input->urlSegment1);
if(empty($username)) throw new Wire404Exception();
$page = $users->get($username);
if(!$page->id) throw new Wire404Exception();
// prevent superuser or users that don't have a specific role from being viewed
if($page->isSuperuser() || !$page->hasRole('some-role-you-want')) throw new Wire404Exception(); 
$page->of(true);

// now you can continue just as if this were the user template
// as $page now represents a user

As for finding users by role, try adding "check_access=0" or "include=all" to the selector. Those user pages are going to be protected from normal access, so adding one of those to the selector makes them accessible to the find().

  • Like 5
Link to comment
Share on other sites

Unless you can find some way to use the existing user pages for this purpose… They are protected under the admin, somewhere you probably don't want your public users going. But like you saw, it's pretty easy to make any other page behave as a user page by using URL segments. So that's probably the way I'd do it.

Link to comment
Share on other sites

Sorry to dig this up again Ryan but I don't quite understand your code above.

If I wanted to replicate having a user "profile" for a student but not use the default "user" template, how could I go about logging in a student and for them to see their profile with only the files they are allowed to see?

Would I log them in and then redirect them to student/my-name (where my-name is a current username - I see that I'd still have to add a student page and a user for each student?)

Sorry just struggling to get my head round this one :)

Link to comment
Share on other sites

I'm trying to implement something similar to what onjegolders is trying to do.

My problem has to do with redirecting the user to the page. For example I have this below in a custom login form:

if($user->isSuperuser()) {
$session->redirect('/admin/');
}
elseif ($user->hasRole(editor)) {
$session->redirect('/admin/');
 }
 else {
	 $session->redirect('/members/');	
 }

But I need a variable to redirect the user to "their" page. I have already set up a new user with roles and a unique template.

So something like this:

elseif ($user->hasRole(guest-member)) {
$session->redirect('/UNIQUE PAGE PATH TO USER/');
 }

Where UNIQUE PAGE PATH TO USER is based on their login info in this case their user name and password.

Any suggestions?

Link to comment
Share on other sites

In a non-technical way, I think that you need to set a variable to the page-name and check that it equals the username to allow access.

If you just want a sort of profile page you can set up a profile template and only display the $user information for that user.

Sorry if this isn't that clear but al struggling with the concept also!

Link to comment
Share on other sites

In a non-technical way, I think that you need to set a variable to the page-name and check that it equals the username to allow access.

If you just want a sort of profile page you can set up a profile template and only display the $user information for that user.

This is exactly correct. Lets say you've got this page /user-profile/ in your site. You also have a template called user-profile, and it has URL segments enabled. In the code, all you need to authenticate is to compare $user->name to $input->urlSegment1. Meaning if user 'onjegolders' accessed the URL: /user-profile/onjegolders then you would allow them to make changes to their profile.

if(!$user->isGuest() && $user->name === $input->urlSegment1) {

 // user is authenticated and may change their password
 if($input->post->submit_pass) {
   if($input->post->pass !== $input->post->pass_confirm) {
     echo "<h2>Passwords do not match!</h2>";

   } else if(strlen($input->post->pass) < 6) {
     // if you want to enforce a minimum password length (recommended)
     echo "<h2>Your password is too short. Must be 6 characters or more.</h2>";

   } else {
     $user->of(false);
     $user->pass = $input->post->pass; 
     $user->save();
     $user->of(true);
     echo "<h2>Your password has been changed</h2>";
   }
 } 

 echo "<form action='{$page->url}{$user->name}' method='post'>";
 echo "<p><label for='pass'>Change your password</label>";
 echo "<input type='password' name='pass' /> ";
 echo "Confirm: <input type='password' name='pass_confirm' /></p> ";
 echo "<input type='submit' name='submit_pass' />";
 echo "</form>"; 
}

The above was just written in the browser so may need tweaks.

  • Like 5
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...