Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uBus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chiara Veronica Señires
uBus
Commits
7a3a60cb
Commit
7a3a60cb
authored
Nov 29, 2015
by
Ian De La Cruz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added reloading. Completely working
parent
4015d74a
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
142 deletions
+146
-142
main.js
CS123-uBus-cloud/cloud/main.js
+95
-0
app.js
web-app/js/app.js
+46
-142
reload.html
web-app/reload.html
+4
-0
viewTrip.html
web-app/viewTrip.html
+1
-0
No files found.
CS123-uBus-cloud/cloud/main.js
View file @
7a3a60cb
...
...
@@ -4,3 +4,98 @@
Parse
.
Cloud
.
define
(
"hello"
,
function
(
request
,
response
)
{
response
.
success
(
"Hello world!"
);
});
Parse
.
Cloud
.
define
(
"reloadUser"
,
function
(
request
,
response
){
if
(
!
request
.
user
)
{
response
.
error
(
"Must be signed in to call this Cloud Function."
)
return
;
}
// The user making this request is available in request.user
// Make sure to first check if this user is authorized to perform this change.
// One way of doing so is to query an Admin role and check if the user belongs to that Role.
// Replace !authorized with whatever check you decide to implement.
var
authorized
;
var
queryAdmin
=
new
Parse
.
Query
(
Parse
.
Role
);
queryAdmin
.
equalTo
(
'name'
,
'Administrator'
);
queryAdmin
.
first
({
success
:
function
(
result
)
{
var
role
=
result
;
var
adminRelation
=
new
Parse
.
Relation
(
role
,
'users'
);
var
queryAdmins
=
adminRelation
.
query
();
queryAdmins
.
equalTo
(
'username'
,
request
.
params
.
userID
);
queryAdmins
.
first
()
.
then
(
function
(
res
){
authorized
=
true
;
},
function
(
err
){
var
queryClerk
=
new
Parse
.
Query
(
Parse
.
Role
);
queryClerk
.
equalTo
(
'name'
,
'Clerk'
);
queryClerk
.
first
({
success
:
function
(
res
){
var
role
=
res
;
console
.
log
(
role
);
var
adminRelation
=
new
Parse
.
Relation
(
role
,
'users'
);
var
queryAdmins
=
adminRelation
.
query
();
queryAdmins
.
equalTo
(
'username'
,
request
.
params
.
userID
);
queryAdmins
.
first
({
success
:
function
(
res
){
authorized
=
true
;
},
error
:
function
(
err
){
response
.
error
(
"Error "
+
err
.
code
+
" : "
+
err
.
message
);
}
});
},
error
:
function
(
err
){
response
.
error
(
"Error "
+
err
.
code
+
" : "
+
err
.
message
);
}
});
});
},
error
:
function
(
error
)
{
if
(
!
authorized
)
{
response
.
error
(
"Not an Admin."
+
request
.
params
.
userID
)
return
;
}
}
});
// The rest of the function operates on the assumption that request.user is *authorized*
Parse
.
Cloud
.
useMasterKey
();
// Query for the user to be modified by username
// The username is passed to the Cloud Function in a
// key named "username". You can search by email or
// user id instead depending on your use case.
var
query
=
new
Parse
.
Query
(
Parse
.
User
);
query
.
equalTo
(
"objectId"
,
request
.
params
.
objectID
);
// Get the first user which matches the above constraints.
query
.
first
({
success
:
function
(
anotherUser
)
{
// Successfully retrieved the user.
// Modify any parameters as you see fit.
// You can use request.params to pass specific
// keys and values you might want to change about
// this user.
var
credit
=
parseInt
(
anotherUser
.
get
(
"creditsRemaining"
));
var
add
=
parseInt
(
request
.
params
.
credits
);
credit
=
parseInt
(
credit
+
add
);
anotherUser
.
set
(
"creditsRemaining"
,
credit
);
// Save the user.
anotherUser
.
save
(
null
,
{
success
:
function
(
anotherUser
)
{
// The user was saved successfully.
response
.
success
(
"Successfully updated user."
);
},
error
:
function
(
gameScore
,
error
)
{
// The save failed.
// error is a Parse.Error with an error code and description.
response
.
error
(
"Could not save changes to user."
);
}
});
},
error
:
function
(
error
)
{
response
.
error
(
"Could not find user."
);
}
});
});
web-app/js/app.js
View file @
7a3a60cb
This diff is collapsed.
Click to expand it.
web-app/reload.html
View file @
7a3a60cb
...
...
@@ -31,6 +31,10 @@
<span>
Cellphone Number:
</span>
<input
type=
"text"
id=
"cellNum"
placeholder=
"09xxxxxxxxx"
>
</label>
<label
class=
"reload__num"
>
<span>
Cellphone Number:
</span>
<input
type=
"number"
id=
"amount"
placeholder=
"100"
>
</label>
<button
class=
"reload__btn"
id=
"searchBtn"
>
Search
</button>
</form>
...
...
web-app/viewTrip.html
View file @
7a3a60cb
...
...
@@ -9,6 +9,7 @@
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/style.css"
>
<script
type=
"text/javascript"
src=
"js/jquery-2.1.4.js"
></script>
<script
src=
"js/parse-1.6.7.js"
></script>
<script
type=
"text/javascript"
src=
"js/moment.js"
></script>
<script
type=
"text/javascript"
src=
"js/app.js"
></script>
</head>
<body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment