@@ -97,7 +97,7 @@ def get_influencers_by_tag(tag_str):
9797 all_influ = dbc .get_all_influencer ()
9898 match_list = da .get_match_influ (tag_str , all_influ )
9999 res = match_list
100- # Return error if and only if connection error
100+ # Return error if and only if connection error
101101 except Exception :
102102 return jsonify ("error" )
103103 return jsonify (res )
@@ -114,6 +114,40 @@ def get_one_user(username):
114114 return jsonify (res )
115115
116116
117+ @app .route ('/influco.api/username/<string:username>' , methods = ['post' ])
118+ def update_username (username ):
119+ response_object = {'status' : 'fail' }
120+ try :
121+ new_name = request .get_json ().get ("new_name" )
122+ # cannot update duplicate
123+ user = dbc .get_one_user (new_name )
124+ if user :
125+ return jsonify (response_object )
126+ res = dbc .update_username (username , new_name )
127+ # no error message
128+ if not isinstance (res , str ):
129+ response_object ['status' ] = 'success'
130+ response_object ['data' ] = res
131+ except Exception :
132+ return jsonify ({'status' : 'error' })
133+ return jsonify (response_object )
134+
135+
136+ @app .route ('/influco.api/password/<string:username>' , methods = ['post' ])
137+ def update_password (username ):
138+ response_object = {'status' : 'fail' }
139+ try :
140+ password = request .get_json ().get ("password" )
141+ res = dbc .update_password (username , password )
142+ # no error message
143+ if not isinstance (res , str ):
144+ response_object ['status' ] = 'success'
145+ response_object ['data' ] = res
146+ except Exception :
147+ return jsonify ({'status' : 'error' })
148+ return jsonify (response_object )
149+
150+
117151@app .route ('/influco.api/register/<string:username>' , methods = ['put' ])
118152def register (username ):
119153 """get info for one user"""
@@ -147,9 +181,7 @@ def login(username):
147181 user_info = dbc .get_one_user (data ["username" ])
148182 if not user_info :
149183 return jsonify (response_object )
150- ############## will be replaced ##############
151184 if user_info ['password' ] != data ["password" ]:
152- ##############################################
153185 return jsonify (response_object )
154186 response_object ['status' ] = 'success'
155187 # Frontend: get user data
0 commit comments