def createNotification(): obj = request.get_json(silent=True) if not helpers.verify_recaptcha(obj['recaptcha']): err = helpers.generateError('Incorrect recaptcha', 400) return helpers.handleResponse(err) res = dbapi.createNotification(obj) useMail = False #Mailing disabled for now if useMail and 'data' in res: to = app.config['MAIL_NOTIFY_GROUP'] #to = dbapi.getAdminMailList() subject = "Ny intresseanmälan" html = render_template('notify.html') helpers.send_email(to, subject, html) return helpers.handleResponse(res, 200)
def uploadImages(): if request.method == 'POST': res = {'data':{'uploaded':[], 'failed':[]}} for filename in request.files: try: new_file = request.files[filename] upload = photos.save(new_file) except UploadNotAllowed: res['data']['failed'].append(filename) else: path = "{}{}/{}".format( app.config['UPLOADS_DEFAULT_DEST'], app.config['IMAGES_DEST'], upload) dbentry = dbapi.createImage(upload, path) if 'data' in dbentry: res['data']['uploaded'].append(dbentry) return helpers.handleResponse(res) err = helpers.generateError('Bad request', 400) return helpers.handleResponse(err)
def changeEmail(): obj = request.get_json(silent=True) user = dbapi.getUserByName(get_jwt_identity()).to_json() obj['uid'] = user['id'] res = dbapi.changeEmail(obj) if 'data' in res: to = dbapi.getAdminMailList() subject = "Prenumeration på räknamedchristin" html = render_template('subscription.html') helpers.send_email(to, subject, html) return helpers.handleResponse(res, 200)
def login(): obj = request.get_json(silent=True) if 'username' not in obj: err = helpers.generateError('username missing', 400) return helpers.handleResponse(err) if 'password' not in obj: err = helpers.generateError('password missing', 400) return helpers.handleResponse(err) if not verifyLogin(obj['username'], obj['password']): err = helpers.generateError('incorrect username or password', 400) return helpers.handleResponse(err) access_token = create_access_token(identity=obj['username']) refresh_token = create_refresh_token(identity=obj['username']) res = {} res['data'] = { 'accessToken': access_token, 'refreshToken': refresh_token, } return helpers.handleResponse(res, 200)
def getUnread(): res = {} res['data'] = dbapi.getUnread() return helpers.handleResponse(res)
def changeUnread(): obj = request.get_json(silent=True) res = dbapi.changeUnread(obj['nid'], obj['checked']) return helpers.handleResponse(res)
def logoutRefresh(): jti = get_raw_jwt()['jti'] res = {} res['data'] = dbapi.blacklistToken(jti) return helpers.handleResponse(res)
def getUser(): res = {} res['data'] = dbapi.getUserByName(get_jwt_identity()).to_json() return helpers.handleResponse(res)
def refreshAccessToken(): username = get_jwt_identity() res = {} res['data'] = { 'accessToken': create_access_token(identity=username) } return helpers.handleResponse(res, 200)
def deleteImages(): obj = request.get_json(silent=True) images_idx = obj['delete_images'] res = dbapi.deleteImages(images_idx) return helpers.handleResponse(res, 204)
def getImages(index): res = {} res['data'] = dbapi.getImages(index) return helpers.handleResponse(res)
def deleteNotification(nid): res = dbapi.deleteNotification(nid) return helpers.handleResponse(res, 204)
def getNotifications(index): res = {} res['data'] = dbapi.getNotifications(index) return helpers.handleResponse(res)