<?php

namespace app\matchmaker\controller;

use app\matchmaker\model\MatchmakerModel;
use cmf\controller\HomeBaseController;

class LoginController extends HomeBaseController
{
    /**
     * 登录
     */
    public function index()
    {
        return $this->fetch();
    }

    public function login()
    {
        $param = $this->request->param();

        if (empty($param['mobile']) || empty($param['password'])) {
            $this->error('请输入手机号或密码');
        }

        $matchmaker = MatchmakerModel::where('mobile',$param['mobile'])->find();
        if (empty($matchmaker)) {
            $this->error('手机号错误');
        }

        if ($matchmaker['status'] != 1) {
            $this->error('该账号已经被封禁');
        }

        if ($matchmaker['password'] != $param['password']) {
            $this->error('密码错误');
        }

        session('matchmaker.id',$matchmaker['id']);
        $this->success('登录成功');
    }

    /**
     * 退出登录
     */
    public function logout()
    {
        session("matchmaker", null);//只有前台用户退出
        return redirect(cmf_url("matchmaker/Login/index"));
    }
}
