Marvin Posted February 11, 2021 Posted February 11, 2021 Hello, 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). <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } 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'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } 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"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div>
monchu Posted February 11, 2021 Posted February 11, 2021 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'))) { $user->of(false); $user->addRole('new-role'); $user->save(); $user->of(true); } });
Marvin Posted February 12, 2021 Author Posted February 12, 2021 Hi @monchu Kabar baik, bagaimana denganmu? (I'm fine thank you, how about you?) So, i need to add the hook function, should i create a file name ready.php or i can search at my processwire installation folder?
monchu Posted February 13, 2021 Posted February 13, 2021 Yes you can create a new file ready.php so you can put the hook snippet there https://github.com/processwire/processwire/blob/master/site-default/ready.php
Marvin Posted February 15, 2021 Author Posted February 15, 2021 Hi @monchu, Sorry i late reply, ok thanks for suggetion, i will try your suggestion and will update very soon for the result, but i want to ask one thing, how i can call hook at login.php? Thank you very much
Marvin Posted February 17, 2021 Author Posted February 17, 2021 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now