Merge branches 'QA' and 'master' of https://github.com/sagidayan/SE-Hub into QA

This commit is contained in:
etyemyer 2015-06-16 23:15:38 +03:00
commit 1f01d2522d
9 changed files with 262 additions and 85 deletions

View file

@ -57,7 +57,7 @@ def create_course(token):
403 - Invalid token or not a lecturer 403 - Invalid token or not a lecturer
""" """
if not request.data: if not request.data:
return bad_request() return bad_request("no data")
if not is_lecturer(token): #todo: change to lecturer id if not is_lecturer(token): #todo: change to lecturer id
return forbidden("Invalid token or not a lecturer!") return forbidden("Invalid token or not a lecturer!")
@ -77,20 +77,20 @@ def create_course(token):
if end_date <= start_date: if end_date <= start_date:
return bad_request("end date cant be before (or same day) start date") return bad_request("end date cant be before (or same day) start date")
course = Course(courseName=payload['courseName'], campusName=payload['campusName'], course = Course(courseName=payload['courseName'], campusName=payload['campusName'], master_id=user.key().id(),
startDate=start_date, endDate=end_date) startDate=start_date, endDate=end_date)
#check if name already exists #check if name already exists
try: try:
query = Course.all() query = Course.all()
query.filter("courseName = ", payload['courseName']) query.filter("courseName = ", payload['courseName'])
for c in query.run(limit=1): for c in query.run(limit=1):
return forbidden("Campus with same name already exists") return forbidden("Course with same name already exists")
except Exception as e: except Exception as e:
print e print e
except Exception: except Exception as e:
print e
return bad_request() return bad_request()

View file

@ -60,14 +60,14 @@ def getUserByToken(token):
403 - No User Found 403 - No User Found
""" """
query = User.all() query = User.all()
query.filter("seToken = ", token) query.filter("seToken =", token)
for u in query.run(limit=5): for u in query.run(limit=5):
return Response(response=u.to_JSON(), return Response(response=u.to_JSON(),
status=200, status=200,
mimetype="application/json") # Real response! mimetype="application/json") # Real response!
return bad_request("No User Found") return no_content("No User Found")
@user_routes.route('/api/users/updateUser/<string:token>', methods=["POST"]) @user_routes.route('/api/users/updateUser/<string:token>', methods=["POST"])
@ -83,8 +83,9 @@ def updateUser(token):
<b>Payload</b><br> <b>Payload</b><br>
- JSON Object, Example: <br> - JSON Object, Example: <br>
{<br> {<br>
'name': 'Campus name',<br> 'name': 'new name',<br>
'isLecturer': '@campus.ac.com',<br> 'isLecturer': true,<br>
'campusName': 'JCE'<br>
}<br> }<br>
<br> <br>
<b>Response</b> <b>Response</b>
@ -100,23 +101,29 @@ def updateUser(token):
try: try:
payload = json.loads(request.data) payload = json.loads(request.data)
except Exception as e: except Exception as e:
return bad_request(e) return bad_request()
user = get_user_by_token(token) user = get_user_by_token(token)
if user is None: if user is None:
return bad_request("Not a user!") return bad_request("Not a user!")
try: try:
user.name = payload['user'] user.name = payload['name']
except Exception:
pass
try:
user.campusName = payload['campusName']
except Exception: except Exception:
pass pass
try: try:
user.isLecturer = payload['isLecturer'] user.isLecturer = payload['isLecturer']
except Exception: except Exception as e:
pass print e
db.put(user)
db.save
return ok("User updated") return ok("User updated")

View file

@ -12,6 +12,7 @@ class User(db.Model):
seToken = db.StringProperty(required=True) seToken = db.StringProperty(required=True)
avatar_url = db.StringProperty(required=True) avatar_url = db.StringProperty(required=True)
isFirstLogin = db.BooleanProperty(default=True) isFirstLogin = db.BooleanProperty(default=True)
campusName = db.StringProperty(required=True, default=" ")
campuses_id_list = db.StringListProperty(default=[]) campuses_id_list = db.StringListProperty(default=[])
classes_id_list = db.StringListProperty(default=[]) classes_id_list = db.StringListProperty(default=[])

View file

@ -147,9 +147,9 @@ body.noscroll
.createCampus .createCampus
{ {
position:relative; position:relative;
/*float:right;*/
} }
/*div.img campusAvatar /*div.img campusAvatar
{ {
border: 1px solid #0000ff; border: 1px solid #0000ff;
@ -164,10 +164,86 @@ body.noscroll
border-left: 2px black solid; border-left: 2px black solid;
border-right: 2px black solid; border-right: 2px black solid;
border-radius: 1px black solid; border-radius: 1px black solid;
}*/ }*/
.gray-font{ .gray-font{
color: #7f7f7f; color: #7f7f7f;
font-size: 300%; font-size: 300%;
text-shadow:#e0e0e0 1px 1px 0; text-shadow:#e0e0e0 1px 1px 0;
} }
.user-pane-menu{
width: 100%;
height: 15%;
background-color: #3F51B5;
-webkit-box-shadow: 0px 13px 34px -14px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 13px 34px -14px rgba(0,0,0,0.75);
box-shadow: 0px 13px 34px -14px rgba(0,0,0,0.75);
top: 20px;
position: relative;
}
.user-pane-menu img{
border: 7px rgb(255, 255, 255) solid;
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 50px;
width: 30%;
/*top: -40px;*/
position: relative;
z-index: 50;
}
.se-menu{
/*margin-top: 20%; */
}
.se-menu ul{
list-style: none;
padding: 0;
padding-left: 0;
}
.se-menu li{
width: 100%;
padding: 15px 0px 15px 15px;
font-size: 150%;
}
.se-menu li:hover{
background-color: #E2E2E2;
font-weight: bold;
}
.se-menu li:active{
background-color: #B2B2B2;
text-shadow:#e0e0e0 1px 1px 0;
font-weight: bold;
}
.se-menu .selected{
background-color: #E2E2E2;
text-shadow:#e0e0e0 1px 1px 0;
font-weight: bold;
}
.user-box{
width: 100%
}
.user-box img{
width: 100%;
border: 4px #7f7f7f solid;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.user-data{
margin-top: auto;
}
.se-menu ul a{
text-decoration: none !important;
color: #7f7f7f;
}

View file

@ -6,5 +6,4 @@ angular.module('SeHub')
{ {
}]); }]);

View file

@ -1,28 +1,76 @@
angular.module('SeHub') angular.module('SeHub')
.controller('mainController', ['$scope', '$rootScope', 'apiService', '$cookies', '$location', function ($scope, $rootScope, apiService, $cookies, $location) { .controller('mainController', ['$scope', '$rootScope', 'apiService', '$cookies', '$location', function($scope, $rootScope, apiService, $cookies, $location) {
var token = $cookies['com.sehub.www']; var token = $cookies['com.sehub.www'];
$scope.loadingData = true; $scope.loadingData = true;
$scope.isInRegisterMode = false; $scope.isInRegisterMode = false;
apiService.getUserByToken(token).success(function(data){ apiService.getUserByToken(token).success(function(data) {
if(data.message == 'No User Found'){ if (data.message == 'No User Found') {
console.error("No User Found!"); console.error("No User Found!");
} }
$scope.user = data; $scope.user = data;
if($scope.user.isFirstLogin){ if ($scope.user.isFirstLogin) {
$scope.menuObj = {}; $scope.menuObj = {};
$scope.isInRegisterMode = true; $scope.isInRegisterMode = true;
$scope.loadingData = false; $scope.loadingData = false;
$location.path('/register') $location.path('/register')
}else{ } else {
$location.path('/home') $location.path('/home')
} }
}) })
$scope.loadingData = false; apiService.getUserByToken(token).success(function(data) // Get user token
{
$scope.user = data;
$scope.loadingData = false;
}]); apiService.getAllCampuses($scope.user.seToken).success(function(data) // Get all the campuses
{
$scope.campuses = data;
}).error(function() {
});
});
$scope.menuItems = [{
"title": "Home",
"icon": "fa fa-home",
"style": "selected",
"route": "#/home"
}, {
"title": "My Campuses",
"icon": "fa fa-university",
"style": "",
"route": "/campuses"
}, {
"title": "My Classes",
"icon": "fa fa-graduation-cap",
"style": "",
"route": "/campuses"
}, {
"title": "My Projects",
"icon": "fa fa-cube",
"style": "",
"route": "/campuses"
}, {
"title": "Tasks",
"icon": "fa fa-clipboard",
"style": "",
"route": "/campuses"
}, {
"title": "Settings",
"icon": "fa fa-cogs",
"style": "",
"route": "#/Settings"
}, {
"title": "Log Out",
"icon": "fa fa-power-off",
"style": "",
"route": "#/logout"
}];
}]);

View file

@ -76,37 +76,69 @@ angular.module('SeHub')
}; };
$scope.lecturer = function(ev) $scope.createCampus = function(ev)
{ {
console.log("inside");
$scope.createCampusClicked = true; $scope.createCampusClicked = true;
if(!$scope.isLecturer) // if i am a lecturer (when pressing -> getting last data value before pressing) = "!isLecturer" it means => I Am Lecturer if(!$scope.isLecturer) // "!isLecturer" Means => I Am Lecturer; if i am a lecturer (when pressing -> getting last data value before pressing)
{ {
// var jsonCreateCampus = if($scope.user.campusSuffixMail != null)
// {
// "title": "Create Campus",
// "email": "email_ending",
// "avatar": "self.avatar.url"
// }
console.log("YES lecturer " + $scope.jsonCreateCampus.title);
if($scope.user.lecAcMail != null)
{ {
apiService.sendValidationMail($scope.user.seToken, $scope.user.lecAcMail).success(function(data) validateEmail($scope.user.campusSuffixMail);
{
console.log("DONE - 200");
$mdDialog.show($mdDialog.alert().title('E-mail Verification').content('A verification e-mail has been sent to your email address.')
.ariaLabel('Email verification alert dialog').ok('Got it!').targetEvent(ev)); // Pop-up alert for e-mail verification
// TODO ADD delete cookies and redirect only after pressed 'Got it'
$cookieStore.remove("com.sehub.www"); // Removing the cookies
$window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page
}).error(function()
{
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address or in the campus name.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
});
} }
} }
} }
validateEmail = function(email) // TODO ADD IT
{
var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
console.log("Email: " + email);
if (!result.test(email))
{
console.log(email + ", Error in email, should alert");
alert('Please provide a valid e-mail address');
}
if(result.test(email))
{
console.log("Im good");
apiService.sendValidationMail($scope.user.seToken, email).success(function(data)
{
console.log("DONE - 200");
$mdDialog.show($mdDialog.alert().title('E-mail Verification').content('A verification e-mail has been sent to your email address.')
.ariaLabel('Email verification alert dialog').ok('Got it!').targetEvent(email)); // Pop-up alert for e-mail verification
// TODO ADD delete cookies and redirect only after pressed 'Got it'
$cookieStore.remove("com.sehub.www"); // Removing the cookies
$window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page
}).error(function()
{
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address or in the campus name.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(email));
});
}
}
// TODO FOR LATER - toast
// TODO FOR LATER
// $scope.getPopWindowPosition = function()
// {
// return Object.keys($scope.toastPosition).filter(function(pos)
// {
// return $scope.toastPosition[pos];
// }).join(' ');
// };
// $scope.toastPosition =
// {
// bottom: false,
// top: true,
// left: false,
// right: true
// };
// TODO FOR LATER
// TODO FOR LATER
}]); }]);

View file

@ -21,10 +21,32 @@
</md-toolbar> </md-toolbar>
<div layout="row" flex> <div layout="row" flex>
<md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-sm')"> <md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-sm')">
<md-content> <!-- <div class="user-pane-menu">
<center> <img ng-src="{{user.avatar_url}}" alt="">
<h1><i class="fa fa-compass"></i> Menu</h1> </div> -->
</center> <md-content class="se-menu">
<div ng-if="!isInRegisterMode">
<div class="user-box" layout="row" layout-padding>
<div flex="30"> <!-- Avatar -->
<img ng-src="{{user.avatar_url}}" alt="">
</div>
<div class="user-data" layout="column" flex>
<div>
{{user.name}}
</div>
<div>
{{user.email}}
</div>
</div>
</div>
<ul>
<a ng-repeat="item in menuItems" ng-href="{{item.route}}">
<li ng-class="[item.style]"><i ng-class="item.icon"></i> {{item.title}}</li>
<md-divider ng-if="!$last"></md-divider>
</a>
</ul>
</div>
<div ng-if="loadingData"> <div ng-if="loadingData">
<md-progress-circular></md-progress-circular> <md-progress-circular></md-progress-circular>
</div> </div>

View file

@ -25,19 +25,19 @@
<div> <div>
<div ng-if="user.isLecturer"> <div ng-if="user.isLecturer">
<div> <div>
<md-button ng-click = "lecturer($event)" ng-model="jsonCreateCampus" class="md-raised">Create Campus</md-button> <md-button ng-click = "createCampus($event)" ng-model="jsonCreateCampus" class="md-raised">Create Campus</md-button>
<div class = "createCampus" ng-if="createCampusClicked"> <div class = "createCampus" ng-if="createCampusClicked">
<md-input-container> <md-input-container>
<label>Academic Lecturer Email</label> <label>Academic Suffix Email</label>
<input type="text" ng-disabled="!createCampusClicked" ng-model="user.lecAcMail" required/> <input type="text" ng-model="user.campusSuffixMail" ng-minlength="1" required/>
</md-input-container> </md-input-container>
<md-input-container> <md-input-container>
<label>Campus Name</label> <label>Campus Name</label>
<input type="text" ng-disabled="!createCampusClicked" ng-model="user.campusName" required/> <input type="text" ng-if="createCampusClicked" ng-model="user.campusName" ng-minlength="1" required !important/>
</md-input-container> </md-input-container>
<md-input-container> <md-input-container>
<label>Campus Avatar Url (optional)</label> <label>Campus Avatar Url (optional)</label>
<input type="text" ng-disabled="!createCampusClicked" ng-model="user.newCampusAvatar" required/> <input type="text" ng-if="createCampusClicked" ng-model="user.newCampusAvatar"/>
</md-input-container> </md-input-container>
</div> </div>
</div> </div>
@ -48,7 +48,6 @@
</md-select> </md-select>
</div> </div>
</div> </div>
<div layout="col" layout-align="center center"> <div layout="col" layout-align="center center">
<div> <div>
<div class="campusAvatar" ng-if="campusChecked"> <div class="campusAvatar" ng-if="campusChecked">
@ -76,13 +75,6 @@
</div> </div>
</div> </div>
</div> </div>
<!-- <div> // TODO return
<p>
<b>Note:</b> This setting can be changed in the future. <br>
But Choose Now for easy Registration...
</p>
</div> -->
</md-card> </md-card>
</md-content> </md-content>
</div> </div>