From 8a55e32303b9633c9e5e9901a4490b48551badcb Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Mon, 9 Jul 2012 17:29:37 +0200 Subject: [PATCH] Added user profile editing support --- TODO | 13 - app/Resources/views/main_template.html.twig | 47 +++ .../Controller/DefaultController.php | 40 ++ src/KekRozsak/FrontBundle/Entity/User.php | 27 ++ src/KekRozsak/FrontBundle/Entity/UserData.php | 391 ++++++++++++++++++ .../FrontBundle/Form/Type/UserDataType.php | 79 ++++ .../FrontBundle/Form/Type/UserType.php | 26 +- .../Resources/config/doctrine/User.orm.yml | 8 + .../config/doctrine/UserData.orm.yml | 71 ++++ .../FrontBundle/Resources/config/routing.yml | 5 + .../views/Default/userprofile.html.twig | 14 + web/css/kekrozsak_front.css | 78 +++- 12 files changed, 775 insertions(+), 24 deletions(-) create mode 100644 src/KekRozsak/FrontBundle/Entity/UserData.php create mode 100644 src/KekRozsak/FrontBundle/Form/Type/UserDataType.php create mode 100644 src/KekRozsak/FrontBundle/Resources/config/doctrine/UserData.orm.yml create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Default/userprofile.html.twig diff --git a/TODO b/TODO index d0b7f43..9b1121d 100644 --- a/TODO +++ b/TODO @@ -2,19 +2,6 @@ Article public roles who can access it -UserData - user id - real name - real name public? - self description - email public? - msn address - msn address public? - google talk address - google talk address public? - skype - skype public? - UserForumViewed it should contain records that show the last viewed post in each forum topic diff --git a/app/Resources/views/main_template.html.twig b/app/Resources/views/main_template.html.twig index e0e4894..adcc35b 100644 --- a/app/Resources/views/main_template.html.twig +++ b/app/Resources/views/main_template.html.twig @@ -3,8 +3,38 @@ Kék Rózsák{% block title %}{% endblock %} + +
+
+{% if app.user %} +
+ [avatar] {{ app.user.displayName }} +
+
+ [avatar] + {{ app.user.displayName }}
+ Jogosultság
+
+
Csoportjaim
+ +
Kedvenc Fórum-témáim
+ +
Üzenetek
+
+
+ +
+
+{% endif %} + +
+
+
{% endfor %}
+ {# div#content-wrapper #} + {# div#wrapper #} +
+
+
+ diff --git a/src/KekRozsak/FrontBundle/Controller/DefaultController.php b/src/KekRozsak/FrontBundle/Controller/DefaultController.php index dbfc1db..bce66f7 100644 --- a/src/KekRozsak/FrontBundle/Controller/DefaultController.php +++ b/src/KekRozsak/FrontBundle/Controller/DefaultController.php @@ -4,6 +4,8 @@ namespace KekRozsak\FrontBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use KekRozsak\FrontBundle\Form\Type\UserType; + class DefaultController extends Controller { public function homepageAction() @@ -26,4 +28,42 @@ class DefaultController extends Controller 'article' => $article )); } + + public function profileEditAction() + { + $user = $this->get('security.context')->getToken()->getUser(); + $oldPassword = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:User')->findOneById($user->getId())->getPassword(); + $form = $this->createForm(new UserType(), $user); + + $saveSuccess = false; + $request = $this->getRequest(); + if ($request->getMethod() == 'POST') + { + $form->bindRequest($request); + if ($form->isValid()) + { + if ($user->getPassword() != '') + { + $user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt())); + } + else + { + $user->setPassword($oldPassword); + } + if ($user->getUserData()->getUserId() === null) + { + $user->getUserData()->setUser($user); + } + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($user); + $em->flush(); + // $saveSuccess = true + } + } + + return $this->render('KekRozsakFrontBundle:Default:userprofile.html.twig', array( + 'form' => $form->createView(), + 'saveSuccess' => $saveSuccess, + )); + } } diff --git a/src/KekRozsak/FrontBundle/Entity/User.php b/src/KekRozsak/FrontBundle/Entity/User.php index 0b60ad1..3b2cfef 100644 --- a/src/KekRozsak/FrontBundle/Entity/User.php +++ b/src/KekRozsak/FrontBundle/Entity/User.php @@ -334,4 +334,31 @@ class User implements UserInterface, AdvancedUserInterface { return $this->last_login_at; } + /** + * @var KekRozsak\FrontBundle\Entity\UserData + */ + private $user_data; + + + /** + * Set user_data + * + * @param KekRozsak\FrontBundle\Entity\UserData $userData + * @return User + */ + public function setUserData(\KekRozsak\FrontBundle\Entity\UserData $userData = null) + { + $this->user_data = $userData; + return $this; + } + + /** + * Get user_data + * + * @return KekRozsak\FrontBundle\Entity\UserData + */ + public function getUserData() + { + return $this->user_data; + } } \ No newline at end of file diff --git a/src/KekRozsak/FrontBundle/Entity/UserData.php b/src/KekRozsak/FrontBundle/Entity/UserData.php new file mode 100644 index 0000000..490fec7 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Entity/UserData.php @@ -0,0 +1,391 @@ +user = $user; + $this->user_id = $user->getId(); + return $this; + } + + /** + * Get user + * + * @return KekRozsak\FrontBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } + /** + * @var integer $user_id + */ + private $user_id; + + /** + * @var string $realName + */ + private $realName; + + /** + * @var boolean $realNamePublic + */ + private $realNamePublic; + + + /** + * Set user_id + * + * @param integer $userId + * @return UserData + */ + public function setUserId($userId) + { + $this->user_id = $userId; + return $this; + } + + /** + * Get user_id + * + * @return integer + */ + public function getUserId() + { + return $this->user_id; + } + + /** + * Set realName + * + * @param string $realName + * @return UserData + */ + public function setRealName($realName) + { + $this->realName = $realName; + return $this; + } + + /** + * Get realName + * + * @return string + */ + public function getRealName() + { + return $this->realName; + } + + /** + * Set realNamePublic + * + * @param boolean $realNamePublic + * @return UserData + */ + public function setRealNamePublic($realNamePublic) + { + $this->realNamePublic = $realNamePublic; + return $this; + } + + /** + * Get realNamePublic + * + * @return boolean + */ + public function getRealNamePublic() + { + return $this->realNamePublic; + } + /** + * @var text $selfDescription + */ + private $selfDescription; + + /** + * @var boolean $emailPublic + */ + private $emailPublic; + + + /** + * Set selfDescription + * + * @param text $selfDescription + * @return UserData + */ + public function setSelfDescription($selfDescription) + { + $this->selfDescription = $selfDescription; + return $this; + } + + /** + * Get selfDescription + * + * @return text + */ + public function getSelfDescription() + { + return $this->selfDescription; + } + + /** + * Set emailPublic + * + * @param boolean $emailPublic + * @return UserData + */ + public function setEmailPublic($emailPublic) + { + $this->emailPublic = $emailPublic; + return $this; + } + + /** + * Get emailPublic + * + * @return boolean + */ + public function getEmailPublic() + { + return $this->emailPublic; + } + /** + * @var string $msnAddress + */ + private $msnAddress; + + /** + * @var boolean $msnAddressPublic + */ + private $msnAddressPublic; + + /** + * @var string $googleTalk + */ + private $googleTalk; + + /** + * @var boolean $googleTalkPublic + */ + private $googleTalkPublic; + + /** + * @var string $skype + */ + private $skype; + + /** + * @var boolean $skypePublic + */ + private $skypePublic; + + + /** + * Set msnAddress + * + * @param string $msnAddress + * @return UserData + */ + public function setMsnAddress($msnAddress) + { + $this->msnAddress = $msnAddress; + return $this; + } + + /** + * Get msnAddress + * + * @return string + */ + public function getMsnAddress() + { + return $this->msnAddress; + } + + /** + * Set msnAddressPublic + * + * @param boolean $msnAddressPublic + * @return UserData + */ + public function setMsnAddressPublic($msnAddressPublic) + { + $this->msnAddressPublic = $msnAddressPublic; + return $this; + } + + /** + * Get msnAddressPublic + * + * @return boolean + */ + public function getMsnAddressPublic() + { + return $this->msnAddressPublic; + } + + /** + * Set googleTalk + * + * @param string $googleTalk + * @return UserData + */ + public function setGoogleTalk($googleTalk) + { + $this->googleTalk = $googleTalk; + return $this; + } + + /** + * Get googleTalk + * + * @return string + */ + public function getGoogleTalk() + { + return $this->googleTalk; + } + + /** + * Set googleTalkPublic + * + * @param boolean $googleTalkPublic + * @return UserData + */ + public function setGoogleTalkPublic($googleTalkPublic) + { + $this->googleTalkPublic = $googleTalkPublic; + return $this; + } + + /** + * Get googleTalkPublic + * + * @return boolean + */ + public function getGoogleTalkPublic() + { + return $this->googleTalkPublic; + } + + /** + * Set skype + * + * @param string $skype + * @return UserData + */ + public function setSkype($skype) + { + $this->skype = $skype; + return $this; + } + + /** + * Get skype + * + * @return string + */ + public function getSkype() + { + return $this->skype; + } + + /** + * Set skypePublic + * + * @param boolean $skypePublic + * @return UserData + */ + public function setSkypePublic($skypePublic) + { + $this->skypePublic = $skypePublic; + return $this; + } + + /** + * Get skypePublic + * + * @return boolean + */ + public function getSkypePublic() + { + return $this->skypePublic; + } + /** + * @var string $phoneNumber + */ + private $phoneNumber; + + /** + * @var boolean $phoneNumberPublic + */ + private $phoneNumberPublic; + + + /** + * Set phoneNumber + * + * @param string $phoneNumber + * @return UserData + */ + public function setPhoneNumber($phoneNumber) + { + $this->phoneNumber = $phoneNumber; + return $this; + } + + /** + * Get phoneNumber + * + * @return string + */ + public function getPhoneNumber() + { + return $this->phoneNumber; + } + + /** + * Set phoneNumberPublic + * + * @param boolean $phoneNumberPublic + * @return UserData + */ + public function setPhoneNumberPublic($phoneNumberPublic) + { + $this->phoneNumberPublic = $phoneNumberPublic; + return $this; + } + + /** + * Get phoneNumberPublic + * + * @return boolean + */ + public function getPhoneNumberPublic() + { + return $this->phoneNumberPublic; + } +} diff --git a/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php b/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php new file mode 100644 index 0000000..e0f7889 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php @@ -0,0 +1,79 @@ +add('emailPublic', null, array( + 'label' => 'Publikus legyen az e-mail címed?', + 'help' => 'Ha bejelölöd, a kör többi tagja láthatja az e-mail címedet.', + 'required' => false, + )); + $builder->add('realName', null, array( + 'label' => 'Valódi neved', + 'help' => 'A valódi, polgári neved. Nem kötelező mező, akkor érdemes megadni, ha szeretnéd, hogy a többi tag megtalálhasson különféle közösségi oldalakon.', + )); + $builder->add('realNamePublic', null, array( + 'label' => 'Publikus legyen a valódi neved?', + 'help' => 'Ha bejelölöd, a kör többi tagja láthatja a valódi neved.', + 'required' => false, + )); + $builder->add('selfDescription', null, array( + 'label' => 'Rövid leírás Magadról', + 'help' => 'Írj ide egy rövid leírást saját magadról. Ez mindenképpen megjelenik majd a profilodon, így a többiek tudhatják, hogy mivel is foglalkozol.', + )); + $builder->add('msnAddress', null, array( + 'label' => 'MSN címed', + 'help' => 'Egy MSN cím, amin elérhető vagy.' + )); + $builder->add('msnAddressPublic', null, array( + 'label' => 'Publikus legyen az MSN címed?', + 'help' => 'Ha bejelölöd, a kör többi tagja láthatja az MSN címedet.', + 'required' => false, + )); + $builder->add('googleTalk', null, array( + 'label' => 'Google Talk címed', + 'help' => 'Itt egy olyan GMail-es e-mail címet adhatsz meg, amin elérhető vagy a GMail csevegőben.', + )); + $builder->add('googleTalkPublic', null, array( + 'label' => 'Publikus legyen a Google Talk címed?', + 'help' => 'Ha bejelölöd, a kör többi tagja láthatja a Google Talk címedet.', + 'required' => false, + )); + $builder->add('skype', null, array( + 'label' => 'Skype neved', + 'help' => 'Egy Skype név, amin elérhető vagy.', + )); + $builder->add('skypePublic', null, array( + 'label' => 'Publikus legyen a Skype neved?', + 'help' => 'Ha bejelölöd, a kör többi tagja láthatja a Skype nevedet.', + 'required' => false, + )); + $builder->add('phoneNumber', null, array( + 'label' => 'Telefonszámod', + 'help' => 'Egy telefonszám, amin elérhető vagy. Programszervezéseknél jól jöhet.', + )); + $builder->add('phoneNumberPublic', null, array( + 'label' => 'Publikus legyen a telefonszámod?', + 'help' => 'Ha bejelölöd, a kör többi tagja láthatja a telefonszámodat.', + 'required' => false, + )); + } + + public function getName() + { + return 'user_data'; + } + + public function getDefaultOptions() + { + return array( + 'data_class' => 'KekRozsak\FrontBundle\Entity\UserData' + ); + } +} + diff --git a/src/KekRozsak/FrontBundle/Form/Type/UserType.php b/src/KekRozsak/FrontBundle/Form/Type/UserType.php index 492299e..98121d7 100644 --- a/src/KekRozsak/FrontBundle/Form/Type/UserType.php +++ b/src/KekRozsak/FrontBundle/Form/Type/UserType.php @@ -4,11 +4,13 @@ namespace KekRozsak\FrontBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use KekRozsak\FrontBundle\Form\Type\UserDataType; + class UserType extends AbstractType { protected $_registration; - public function __construct($registration) + public function __construct($registration = false) { $this->_registration = $registration; } @@ -17,12 +19,14 @@ class UserType extends AbstractType { $builder->add('username', null, array( 'label' => 'Felhasználónév', + 'read_only' => (!$this->_registration), 'help' => 'Ezt fogod használni az oldalra való bejelentkezéshez. Jelszavadhoz hasonlóan kezeld bizalmasan! Jelentkezés után nem lehet megváltoztatni!', )); $builder->add('password', 'repeated', array( 'type' => 'password', 'second_name' => 'confirm', 'invalid_message' => 'A két jelszó nem egyezik meg!', + 'required' => ($this->_registration), 'options' => array( 'label' => 'Jelszó', 'help' => 'Ezt fogod használni az oldalra való bejelentkezéshez. Soha ne add meg senkinek!', @@ -30,16 +34,26 @@ class UserType extends AbstractType )); $builder->add('email', null, array( 'label' => 'E-mail cím', + 'help' => 'Ezen az e-mail címen értesítünk majd, ha felvételt nyersz a körbe.', )); $builder->add('displayName', null, array( 'label' => 'Név', 'help' => 'Ezen a néven fog szólítani a közösség. Bármikor megváltoztathatod, de az egyértelműség kedvéért ezt mindig jelezd a többiek felé!', )); - $builder->add('agree', 'checkbox', array( - 'property_path' => false, - 'label' => ' ', - 'help' => 'A Jelentkezés gomb megnyomásával kijelentem, hogy a Kék Rózsa okkultista kör Házirendjét elolvastam, és azt felvételem esetén magamra nézve teljes mértékben elfogadom.', - )); + if (!$this->_registration) + { + $builder->add('user_data', new UserDataType(), array( + 'label' => 'Egyéb adatok', + )); + } + else + { + $builder->add('agree', 'checkbox', array( + 'property_path' => false, + 'label' => ' ', + 'help' => 'A Jelentkezés gomb megnyomásával kijelentem, hogy a Kék Rózsa okkultista kör Házirendjét elolvastam, és azt felvételem esetén magamra nézve teljes mértékben elfogadom.', + )); + } } public function getName() diff --git a/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml b/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml index ac18718..70e6170 100644 --- a/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml +++ b/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml @@ -41,3 +41,11 @@ KekRozsak\FrontBundle\Entity\User: manyToMany: roles: targetEntity: Role + oneToOne: + user_data: + targetEntity: UserData + mappedBy: user + joinColumns: + id: + referencedColumnName: user_id + cascade: [ 'persist' ] diff --git a/src/KekRozsak/FrontBundle/Resources/config/doctrine/UserData.orm.yml b/src/KekRozsak/FrontBundle/Resources/config/doctrine/UserData.orm.yml new file mode 100644 index 0000000..fab2a4b --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/config/doctrine/UserData.orm.yml @@ -0,0 +1,71 @@ +KekRozsak\FrontBundle\Entity\UserData: + type: entity + table: user_data + id: + user_id: + type: integer + fields: + emailPublic: + type: boolean + nullable: false + default: false + realName: + name: real_name + type: string(100) + nullable: true + default: null + realNamePublic: + name: real_name_public + type: boolean + nullable: true + default: false + selfDescription: + name: self_description_public + type: text + nullable: true + default: null + msnAddress: + name: msn + type: string(100) + nullable: true + default: null + msnAddressPublic: + name: msn_public + type: boolean + nullable: false + default: false + googleTalk: + name: google_talk + type: string(100) + nullable: true + default: null + googleTalkPublic: + name: goole_talk_public + type: boolean + nullable: false + default: false + skype: + type: string(100) + nullable: true + default: null + skypePublic: + name: skype_public + type: boolean + nullable: false + default: false + phoneNumber: + name: phone_number + type: string(30) + nullable: true + phoneNumberPublic: + name: phone_number_public + type: boolean + nullable: false + default: false + oneToOne: + user: + targetEntity: User + inversedBy: user_data + joinColumns: + user_id: + referencedColumnName: id diff --git a/src/KekRozsak/FrontBundle/Resources/config/routing.yml b/src/KekRozsak/FrontBundle/Resources/config/routing.yml index 2e304b3..2b0fc09 100644 --- a/src/KekRozsak/FrontBundle/Resources/config/routing.yml +++ b/src/KekRozsak/FrontBundle/Resources/config/routing.yml @@ -31,3 +31,8 @@ KekRozsakFrontBundle_forum_new_post: _controller: KekRozsakFrontBundle:Forum:postList requirements: _method: POST + +KekRozsakFrontBundle_profile_edit: + pattern: /profil + defaults: + _controller: KekRozsakFrontBundle:Default:profileEdit diff --git a/src/KekRozsak/FrontBundle/Resources/views/Default/userprofile.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Default/userprofile.html.twig new file mode 100644 index 0000000..a7021ee --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Default/userprofile.html.twig @@ -0,0 +1,14 @@ +{% extends '::main_template.html.twig' %} +{% form_theme form 'KekRozsakFrontBundle:Form:user_form.html.twig' %} +{% block title %} - Profil szerkesztése{% endblock %} +{% block content %} +

Felhasználói profil

+

Az itt megadott adataidat szigorúan kezeljük, azt más számára kizárólag hatósági felszólításra adjuk ki.

+

A publikusnak megjelölt adataidat csak a kör tagjai láthatják, míg a nem publikusnak megjelölteket kizárólag az oldal adminisztrátorai.

+
+ +{{ form_widget(form) }} +
+ +
+{% endblock content %} diff --git a/web/css/kekrozsak_front.css b/web/css/kekrozsak_front.css index 211b3a0..f493756 100644 --- a/web/css/kekrozsak_front.css +++ b/web/css/kekrozsak_front.css @@ -4,7 +4,7 @@ } body { - margin: 15px 0 0 0; + margin: 0; background-color: black; background-image: url('../images/rose_bg.png'); background-repeat: no-repeat; @@ -12,9 +12,77 @@ body { background-position: right bottom; } +#top-line { + position: fixed; + left: 0; + top: 0; + width: 100%; + background-color: #152967; + color: #c4d3ff; + height: 32px; + border-bottom: 1px solid #1b3586; +} + +#top-line-padding { + height: 33px; + clear: both; +} + +#top-line #search-box { + float: right; + padding: 5px; +} + +#top-line #profil-gomb { + float: left; + padding: 5px; +} + +#bottom-line-padding { + height: 33px; +} + +#profil-box { + position: fixed; + left: 5px; + top: 32px; + width: 300px; + height: 400px; + background-color: #c4d3ff; + border: 2px solid #152967; + color: #152967; + display: none; +} + +#profil-belso { + position: relative; + padding: 5px; +} + +#profil-box dt { + font-weight: bold; +} + +#profil-szerkesztes { + position: absolute; + bottom: 5px; + right: 5px; +} + +#bottom-line { + position: fixed; + left: 0; + bottom: 0; + width: 100%; + background-color: #152967; + color: #c4d3ff; + height: 32px; + border-top: 1px solid #1b3586; +} + #wrapper { background-color: #000000; - width: 900px; + width: 960px; margin-left: auto; margin-right: auto; } @@ -68,8 +136,8 @@ body { #content-outline { color:#3366ff; text-align: justify; - width: 680px; - float: right; + width: 740px; + float: left; } #content { @@ -77,7 +145,7 @@ body { } #hirek { - float: left; + float: right; color: #aaaacc; width: 215px; }