model view controller - CodeIgniter - Where to place the logic for authentication (sigin, signup) -


firstly, not software architect, please bear me. need basic understanding, nothing highly academic or pedantic (thin controller vs fat model , debates..)

so scenario helping colleague build signin , signup feature in app developing. using codeigniter very simple mvc framework.

my colleague wrote signin , signup functions inside controller , in functions added necessary db queries , added bunch of helper functions inside controller etc.

since there many opinions on separation of concern within mvc, thinking below role controller:

use controller getting user input, sanitising input, invoking models , passing them data, getting results , rendering views.

with design in mind controller like:

$auth = new authmodel(); if($auth->dologin($user,$pass))   loadview("welcome-page"); else   loadview("login-fail-page"); 

and dologin() in authmodel heavy lifting of querying db etc.

as reasonably "ok-ish" design, suffice? or ok have query , resultset looking , in controller?

sure, that's "ok-ish" within controllers other signup/signin controller need is_logged_in method. used in other controllers this.

if($this->authmodel->is_logged_in() === false) {     redirect('login'); //the "signup/signin" controller } //good go, authenticated user stuff 

i suggest study couple of established , respected codeigniter authentication libraries see how work , used.

  1. ion auth
  2. community auth

there nice tutorial on using ion auth ci here.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -