def fill_social(profile: models.Profile): social_account = SocialAccount.objects.filter(user=profile.user).first() if social_account: data = social_account.extra_data if social_account.provider == 'vk': profile.social_vk = f'https://vk.com/id{data["id"]}' profile.name = f"{data.get('first_name', '')} {data.get('last_name', '')}" profile.city = data['city'].get('title', '') if data.get('city') else '' if data.get('bdate'): profile.birthday = datetime.strptime(data.get('bdate'), '%d.%m.%Y').date() if data.get('email'): profile.social_email = data['email'] if data.get('photo_max_orig'): save_image(profile, data['photo_max_orig'], social_account.provider) elif social_account.provider == 'odnoklassniki': profile.social_ok = f'https://ok.ru/profile/{data["uid"]}' profile.name = data.get('name', '') profile.city = data['location'].get( 'city', '') if data.get('location') else '' if data.get('birthday'): profile.birthday = datetime.strptime(data.get('birthday'), '%Y-%m-%d').date() if data.get('pic1024x768'): save_image(profile, data['pic1024x768'], social_account.provider) elif social_account.provider == 'google': profile.name = data.get('name', '') if data.get('picture'): save_image(profile, data['picture'], social_account.provider) if data.get('email'): profile.social_email = data['email'] elif social_account.provider == 'facebook': profile.social_fb = f'https://www.facebook.com/profile.php?id={data["uid"]}' profile.name = data.get('name', '') if data.get('email'): profile.social_email = data['email'] profile.save()
def register_profile(): if request.method == 'POST': name = request.json.get("name", None) last_name = request.json.get("last_name", None) about_me = request.json.get("about_me", None) github = request.json.get("github", None) linkedin = request.json.get("linkedin", None) twitter = request.json.get("twitter", None) user_id = request.json.get("user_id", None) if not name: return "Email required", 401 username = request.json.get("username", None) if not last_name: return "Username required", 401 password = request.json.get("password", None) if not about_me: return "Password required", 401 if not github: return "Password required", 401 # email_query = User.query.filter_by(user_id=user_id).first() # if email_query: # return "This email has been already taken", 401 profile = Profile() profile.name = name profile.last_name = last_name profile.twitter = twitter profile.github = github profile.linkedin = linkedin profile.user_id = user_id profile.about_me = about_me profile.status = True db.session.add(profile) db.session.commit() response = {"msg": "Added successfully", "github": github} return jsonify(response), 200