-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
104 lines (92 loc) · 2.21 KB
/
Copy pathhelpers.py
File metadata and controls
104 lines (92 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from flask import Flask, request, url_for
import bcrypt, uuid, random, requests
import datetime, time
from __init__ import app
def datetime_to_epoch(date):
return time.mktime(date.timetuple())*1000
'''
To create url for pagination
'''
def url_for_other_page(page):
args = dict(request.args)
args['page'] = page
return url_for(request.endpoint, _external=True, **args)
'''
To hash the password
'''
def hash_password(password):
return bcrypt.hashpw(str(password), bcrypt.gensalt())
'''
To hash the access-token
'''
def access_token():
return bcrypt.hashpw(str(random.random()), bcrypt.gensalt())
'''
To validate/comapre the hash password
@param present - user's account present password
@param requested - password requested for verification
'''
def validate_hash_password(requested, present):
return bcrypt.checkpw(str(requested), str(present))
'''
To generate unique code
uuid package
'''
def generate_unique_code():
return uuid.uuid4().__str__()
'''
error message
'''
def error(message):
return {
'message' : message,
'tags' : 'error'
}
'''
Get redirect function
'''
def get_redirect_resolver(provider):
if provider == 'google':
return 'google_redirect'
if provider == 'facebook':
return 'facebook_redirect'
if provider == 'github':
return 'github_redirect'
'''
get authrization function
'''
def get_authrize_resolver(provider):
if provider == 'google':
return 'google_authorize'
if provider == 'facebook':
return 'facebook_authorize'
if provider == 'github':
return 'github_authorize'
'''
modify an url
'''
def modify_url(url):
local_url = get_local_server_url().split("//")[-1]
return url.replace(url.split("//")[-1].split("/")[0], local_url)
'''
get respective api server url
'''
def get_local_server_url():
if app.config['APP_ENV'] == 'production':
return "http://139.59.71.222"
return "http://localhost:5000"
'''
get feedr url
'''
def get_feedr_url():
if app.config['APP_ENV'] == 'production':
return "http://139.59.4.41/"
return "http://localhost:8000"
'''
success message
'''
def success(message):
return {
'message' : message,
'tags' : 'success'
}