Skip to content

Instantly share code, notes, and snippets.

@ozw-sei
Last active January 2, 2016 05:19
Show Gist options
  • Select an option

  • Save ozw-sei/8256413 to your computer and use it in GitHub Desktop.

Select an option

Save ozw-sei/8256413 to your computer and use it in GitHub Desktop.
ログインの関数。自分ならModelに実装できるように頑張る。
Modelに書く
```
function hogeAction(){
//ユーザ取得
$user = UserModel.get(‘なんか鍵’);
//ユーザModelがログインしてるかどうか判断する
if($user->isLogin()){
return render(‘template.html’, なんかバインドするデータ);
}
else{

//ログインしてない
return redirect(‘どっか’);
}
}
```
継承して使う
```
abstract function login_success();
abstract function login_fail();
function action(){
if(isLogin){
$this->login_success();
}else{
$this->login_fail();
}
}
```
あんまり好きじゃない
```
function hogeAction(){
//ユーザ取得
$user = UserModel.get(session(‘なんか鍵’));
//ヘルパークラスが調べる
if(LoginHelper::isLogin(user)){
return render(‘template.html’, なんかバインドしてないデータ);
}
else{

//ログインしてない
return redirect(‘どっか’);
}
}
```
論外
```
function hogeAction(){
//ユーザ取得
$user = UserModel.get(session(‘なんか鍵’));
/*
ログイン処理
数十行
*/
return render('template.html');
}
```
PythonやRubyならこれが好き
```
設定ファイル
loginurl = '/'
ログインしてたら関数内を処理、してなかったら設定ファイルのログインURLにリダイレクト
@login_required
def act(){
return 'login_success_page.html'
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment