/** * Creates account for new users */ public function actionRegister() { if (!Yii::app()->user->isGuest) { Yii::app()->request->redirect('/'); } $user = new User('register'); $profile = new UserProfile(); if (Yii::app()->request->isPostRequest && isset($_POST['User'], $_POST['UserProfile'])) { $user->attributes = $_POST['User']; $profile->attributes = $_POST['UserProfile']; $valid = $user->validate(); $valid = $profile->validate() && $valid; if ($valid) { $user->save(); $profile->save(); $profile->setUser($user); // Add user to authenticated group Yii::app()->authManager->assign('Authenticated', $user->id); $this->addFlashMessage(Yii::t('UsersModule.core', 'Спасибо за регистрацию на нашем сайте.')); // Authenticate user $identity = new UserIdentity($user->username, $_POST['User']['password']); if ($identity->authenticate()) { Yii::app()->user->login($identity, Yii::app()->user->rememberTime); Yii::app()->request->redirect($this->createUrl('/users/profile/index')); } } } $this->render('register', array('user' => $user, 'profile' => $profile)); }
public function getAllFriends(User $user) { $con = Connection::createConnection(); $result = mysql_query("SELECT u1.id as user_id, u1.username as user_name, u2.* FROM user u1, userprofile u2 where u1.id = u2.id AND u1.id != {$user->id}"); $friendList = array(); while ($row = mysql_fetch_array($result)) { $userProfile = new UserProfile(); $tempUser = new User(); //setting user $tempUser->id = $row['user_id']; $tempUser->username = $row['user_name']; $userProfile->setUser($tempUser); //Setting user profile $userProfile->id = $row['id']; $userProfile->age = $row['age']; $userProfile->country = $row['country']; $userProfile->favgame = $row['favgame']; $userProfile->humour = $row['humour']; $userProfile->imgurl = $row['imgurl']; $userProfile->job = $row['job']; $userProfile->language = $row['language']; $userProfile->politicalview = $row['politicalview']; $userProfile->religion = $row['religion']; $userProfile->school = $row['school']; array_push($friendList, $userProfile); } return $friendList; }
public function getSpyQuestion($user, $gameProgress) { $con = Connection::createConnection(); //first we need to check weather that person has spied him already or not $spy = ServerConstants::SPY; if ($this->canSpy($gameProgress)) { $friendUser = $gameProgress->friend->user; $result = mysql_query("select * from userprofile where userprofile.userid !={$friendUser->id} order by rand() limit 2"); $dataArray = array(); while ($row = mysql_fetch_array($result)) { $userprofile = new UserProfile(); $userprofile->id = $row['id']; $userprofile->setUser($user); $userprofile->age = $row['age']; $userprofile->country = $row['country']; $userprofile->favgame = $row['favgame']; $userprofile->humour = $row['humour']; $userprofile->imgurl = $row['imgurl']; $userprofile->job = $row['job']; $userprofile->language = $row['language']; $userprofile->politicalview = $row['politicalview']; $userprofile->religion = $row['religion']; $userprofile->school = $row['school']; array_push($dataArray, $userprofile); } /* Getting data of friend whom we want to spy i.e. the right options */ $friendProfile = $gameProgress->friend; array_push($dataArray, $friendProfile); Connection::closeConnection($con); return $dataArray; } else { Connection::closeConnection($con); return null; } }
/** * * @param <User> $user * @return <UserProfile> * @SQL Select * From userprofile Where userid=1 */ public function getUserProfile(User $user) { $con = Connection::createConnection(); $result = mysql_query("Select * From userprofile Where userid={$user->id}"); $tempArray = mysql_fetch_array($result); if (mysql_num_rows($result) == 1) { $userprofile = new UserProfile(); $userprofile->id = $tempArray['id']; $userprofile->setUser($user); $userprofile->age = $tempArray['age']; $userprofile->country = $tempArray['country']; $userprofile->favgame = $tempArray['favgame']; $userprofile->humour = $tempArray['humour']; $userprofile->imgurl = $tempArray['imgurl']; $userprofile->job = $tempArray['job']; $userprofile->language = $tempArray['language']; $userprofile->politicalview = $tempArray['politicalview']; $userprofile->religion = $tempArray['religion']; $userprofile->school = $tempArray['school']; } Connection::closeConnection($con); return $userprofile; }