mirror of
https://github.com/fazo96/homework.git
synced 2025-01-10 12:14:22 +01:00
added GUI to change API keys
This commit is contained in:
parent
7169bf3a57
commit
19850b1d20
@ -168,12 +168,16 @@ Template.menu.events
|
||||
# Account Page
|
||||
Template.account.helpers
|
||||
dateformat: -> if getUser() then return getUser().dateformat
|
||||
apikey: -> if getUser() then return getUser().apiKey
|
||||
Template.account.events
|
||||
'click #reset-settings': (e,t) ->
|
||||
t.find('#set-date-format').value = "MM/DD/YYYY"
|
||||
t.find('#set-api-key').value = ''
|
||||
'click #save-settings': (e,t) ->
|
||||
Meteor.users.update getUser()._id,
|
||||
$set: dateformat: t.find('#set-date-format').value
|
||||
$set:
|
||||
dateformat: t.find('#set-date-format').value
|
||||
apiKey: t.find('#set-api-key').value
|
||||
showError msg: 'Settings saved', type: 'success'
|
||||
'click #btn-logout': -> Meteor.logout logoutCallback
|
||||
'click #btn-delete-me': -> deleteAccount()
|
||||
|
@ -161,9 +161,17 @@
|
||||
<template name="account">
|
||||
<div align="center">
|
||||
<h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3>
|
||||
<p class="lead">Settings</p>
|
||||
<p class="lead">Date Format</p>
|
||||
<p>You can choose the format used to write and read dates in the note list</p>
|
||||
<input type="text" class="form-control" id="set-date-format" placeholder="Date Format" value="{{dateformat}}">
|
||||
<hr>
|
||||
<p class="lead">API Key</p>
|
||||
<p>If you want to be able to use our <b>RESTful API</b> or an application that uses it (such as our awesome
|
||||
<a href="https://www.npmjs.com/package/homework-cli">command line client</a>) you need to input an <b>API Key</b>
|
||||
here that will allow the programs to <u>read, write and delete all your notes</u>.</p>
|
||||
<p>you can change this key any time
|
||||
or remove it completely by leaving this field blank.</p>
|
||||
<input type="text" class="form-control" id="set-api-key" placeholder="Your API Key" value="{{apikey}}">
|
||||
<div class="btn-group">
|
||||
<button type="button" id="save-settings" class="btn btn-primary">
|
||||
<i class="fa fa-upload"></i> Save</button>
|
||||
|
@ -4,13 +4,14 @@ if !Meteor.settings.enableAPI? then return
|
||||
|
||||
console.log 'RESTful HTTP API enabled'
|
||||
|
||||
apiKeyToUser = (key) -> Meteor.users.findOne apiKey: key
|
||||
apiKeyToUser = (key) ->
|
||||
if key? and key != "" then Meteor.users.findOne apiKey: key
|
||||
respond = (res, code, obj) ->
|
||||
res.writeHead code, 'Content-Type': 'application/json'
|
||||
res.end JSON.stringify obj
|
||||
|
||||
# GET NOTES
|
||||
Router.route '/api/:key', where: 'server'
|
||||
# GET NOTES
|
||||
.get ->
|
||||
user = apiKeyToUser @params.key
|
||||
if !user
|
||||
|
@ -16,7 +16,7 @@ userValidated = (user) ->
|
||||
return yes for mail in user.emails when mail.verified is yes; no
|
||||
|
||||
Meteor.publish 'user', ->
|
||||
Meteor.users.find @userId, fields: {dateformat: 1, username: 1}
|
||||
Meteor.users.find @userId, fields: {dateformat: 1, username: 1, apiKey: 1}
|
||||
# Publish user's notes to each user.
|
||||
Meteor.publish "notes", (archived) ->
|
||||
if userValidated getUser(@userId)
|
||||
@ -57,7 +57,10 @@ Meteor.methods
|
||||
|
||||
# Allow users to change their date format
|
||||
Meteor.users.allow
|
||||
update: (id,doc,fields,mod) ->
|
||||
if fields[0] == 'dateformat' and fields.length == 1
|
||||
return yes
|
||||
return no
|
||||
update: (id,doc,fields,mod) ->
|
||||
for i,f of fields
|
||||
console.log f
|
||||
unless f in ['dateformat','apiKey']
|
||||
return no
|
||||
yes
|
||||
fetch: ['dateformat','apiKey']
|
||||
|
Loading…
Reference in New Issue
Block a user