Jump to content

Create Login System with access roles


Recommended Posts


My name Marvin and i'm still new at ProcessWire development, i want to change my website authentication system using a PHP and Processwire, i tried to search some reference but get stuck of it, all i want to do just add some roles access to my website authentication system, can some one help me with a suggestion? Thank you very much before.

Here i attach my code below

This for authentication, i create a user like the other template. (I mean as a pages).

  $note = $note2 = $hidden ="";

  if($input->get->id == "logout") {

  if($input->post->submit) {
    $name = $sanitizer->email($input->post->login_name);
    $pass = $sanitizer->text($input->post->login_pass);
    $result = $pages->find("email=$email, text_1=$pass");

  if(!$email || !$pass) {
    $note = "Data belum lengkap";
  } else {
    if($result->count > 0) {
      $session->login_id = "$result";
      $hidden = "style = 'diplay:none'";
    } else {
      $note = "Akun tidak ditemukan";

And this is a Login Form

<div class="frow-container">
  <div class="frow centered mt-50">
    <div class="col-md-1-3">
      <div class="box p-40 shadow-light">
        <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2>
        <form method="post" <?=$hidden?>>
          <label>Username <input type="text" name="login_name"></label>
          <label>Password <input type="password" name="login_pass"></label>
          <input type="submit" name="submit" value="Masuk">
        <p class="notif"><?=$note;?></p>
        <div class="text-center"><?=$note2;?></div>


Link to comment
Share on other sites

Hi Marvin,

Apa kabar?

You can add roles using hook in your ready.php

$this->addHookAfter('Session::loginSuccess', null, function($event) {
	$user = $event->wire('user');

	if (($this->wire('user')->notes) == '') $note = "Data belum lengkap";
	if ((($this->wire('user')->notes) != '') && (!$this->wire('user')->hasRole('new-role'))) {	


Link to comment
Share on other sites

Hi @monchu

Sorry for last update, i was trying your solution, but that doesn't help, now i can't login to my website, anymore and your link is empty, don't have any source code for example, are you give a right link? Because when i get into it, it just empty, and i didn't find anything from it

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

  • Recently Browsing   0 members

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