public static function edit() { # login required decorator self::login_required(); # if user perform the form submit button if ("POST" == Request::method()) { $id = Request::user()->id; $name = Request::POST()->name; $username = Request::POST()->username; $bio = Request::POST()->bio; $profile_picture = File::upload('img', 'change_photo'); $member = Accounts::find(['username' => $username]); if ($member and $member['username'] !== Request::user()->username) { Session::push('flash-message-form', 'That username has used by other member, please use another!'); Response::redirect('profile/' . Request::user()->username); } if ($profile_picture) { Accounts::edit($id, $name, $username, $bio, $profile_picture); } else { Accounts::edit($id, $name, $username, $bio); } # push a flash message Session::push('flash-message', 'Your profile biodata has changed successfully!'); # if username or name has changed # reconfigure the member session data if ($name !== Request::user()->name or $username !== Request::user()->username) { # get member data by id $data = Accounts::findByPK($id); # Set a session ID $account = array($data['id'], $data['username'], $data['name'], $data['type']); $session = new Session(); $session->set('id_account', implode('|', $account)); } # redirect member profile page Response::redirect('profile/' . Request::user()->username); } else { # redirect to home Response::redirect(''); } }