Completed
Push — master ( 00cd39...47d74e )
by Tom
05:36
created

VoteController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Kineo\Controller;
3
4
use Silex\Application;
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Kineo\Component\Database;
8
use Kineo\Component\ApiResponse;
9
use Kineo\Model\UserModel;
10
11
class VoteController
12
{	
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
13
	public function castVoteAction() 
14
	{
15
		$userData = json_decode(file_get_contents('php://input'));
16
		
17
		$userModel = new UserModel(new Database());
18
		
19
		if($userModel->loadUserByEmail($userData->email)) {
20
			return ApiResponse::error('USER_EXISTS');
21
		}
22
		
23
		try {	
24
			$userModel->saveUser($userData->email, $userData->first_name, $userData->surname, $userData->constituency, $userData->voting, $userData->candidate);
25
			
26
			return ApiResponse::success('DEFAULT_RESPONSE_SUCCESS');
27
		} catch(\Exception $e) {
28
			return ApiResponse::error('USER_SAVE_FAIL');
29
		}		
30
	}
31
}