| 1 | <?php |
|---|
| 2 | Rhaco::import('view.Phwittr'); |
|---|
| 3 | Rhaco::import('model.Users'); |
|---|
| 4 | |
|---|
| 5 | class PhwittrUser extends Phwittr |
|---|
| 6 | { |
|---|
| 7 | function signup(){ |
|---|
| 8 | if(RequestLogin::isLoginSession()) |
|---|
| 9 | Header::redirect(Rhaco::url('home')); |
|---|
| 10 | return $this->parser('signup.html'); |
|---|
| 11 | } |
|---|
| 12 | function create(){ |
|---|
| 13 | if($this->isPost()){ |
|---|
| 14 | $this->clearVariable('id', 'image', 'createdAt', 'updatedAt', 'deleteFlag'); |
|---|
| 15 | if($this->dbUtil->insert($this->toObject(new Users()))){ |
|---|
| 16 | return $this->parser('account/create.html'); |
|---|
| 17 | } |
|---|
| 18 | } |
|---|
| 19 | return $this->parser('signup.html'); |
|---|
| 20 | } |
|---|
| 21 | function settings(){ |
|---|
| 22 | $users = $this->loginRequired(); |
|---|
| 23 | $this->setTemplate('settings.html'); |
|---|
| 24 | $this->clearVariable('id', 'userName', 'password', 'createdAt', 'actKey', 'deleteFlag'); |
|---|
| 25 | return parent::update($users); |
|---|
| 26 | } |
|---|
| 27 | function password(){ |
|---|
| 28 | $users = $this->loginRequired(); |
|---|
| 29 | $this->setTemplate('password.html'); |
|---|
| 30 | $this->clearVariable('id', 'userName', 'email', 'password', 'createdAt', 'actKey', 'deleteFlag'); |
|---|
| 31 | return parent::update($users); |
|---|
| 32 | } |
|---|
| 33 | function picture(){ |
|---|
| 34 | $users = $this->loginRequired(); |
|---|
| 35 | if($this->isPost() && $this->isVariable('delete')){ |
|---|
| 36 | @unlink(Rhaco::resource('templates/img/user/'). $users->image); |
|---|
| 37 | $users->image = null; |
|---|
| 38 | $this->dbUtil->update($users); |
|---|
| 39 | Header::redirect(Rhaco::url('account/picture')); |
|---|
| 40 | } |
|---|
| 41 | $this->setTemplate('picture.html'); |
|---|
| 42 | $this->clearVariable('id', 'userName', 'email', 'password', 'createdAt', 'actKey', 'deleteFlag'); |
|---|
| 43 | return parent::update($users); |
|---|
| 44 | } |
|---|
| 45 | function activate($actKey){ |
|---|
| 46 | $users = $this->dbUtil->get(new Users(), new C(Q::eq(Users::columnActKey(), $actKey))); |
|---|
| 47 | if(Variable::istype('Users', $users)){ |
|---|
| 48 | $users->actKey = null; |
|---|
| 49 | if($this->dbUtil->update($users)) |
|---|
| 50 | return $this->parser('account/activated.html'); |
|---|
| 51 | } |
|---|
| 52 | return $this->_notFound(); |
|---|
| 53 | } |
|---|
| 54 | function login(){ |
|---|
| 55 | if(!RequestLogin::isLoginSession()) |
|---|
| 56 | RequestLogin::login(new LoginCondition($this->dbUtil, new Users())); |
|---|
| 57 | if(RequestLogin::isLoginSession()){ |
|---|
| 58 | $redirect_to = $this->getSession('redirect_to', Rhaco::url('home')); |
|---|
| 59 | $this->clearSession('redirect_to'); |
|---|
| 60 | Header::redirect($redirect_to); |
|---|
| 61 | } |
|---|
| 62 | return $this->parser('login.html'); |
|---|
| 63 | } |
|---|
| 64 | function logout(){ |
|---|
| 65 | if(RequestLogin::isLoginSession()) |
|---|
| 66 | RequestLogin::logout(); |
|---|
| 67 | $redirect_to = $this->getSession('redirect_to', Rhaco::url('home')); |
|---|
| 68 | $this->clearSession('redirect_to'); |
|---|
| 69 | Header::redirect($redirect_to); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|