def login_github_relieve(request): thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_id( request.user.id) if thirdpartyUser_find is not None: thirdpartyUser_find.delete() response_dictionary = {'code': 200, 'result': 'success'} return json_httpResponse(response_dictionary)
def change_username_email(request): current = 'change_username_email'; title = u'设置 / 修改用户名和邮箱' thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) response_dictionary = {'current': current, 'title': title, 'thirdpartyUser': thirdpartyUser} return render_to_response('settings/change_username_email.html', response_dictionary, context_instance=RequestContext(request))
def thirdparty(request): current = 'thirdparty'; title = u'设置 / 第三方' thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) response_dictionary = {'current': current, 'title': title, 'thirdpartyUser': thirdpartyUser} return render_to_response('settings/thirdparty.html', response_dictionary, context_instance=RequestContext(request))
def change_username_email(request): current = 'change_username_email' title = u'设置 / 修改用户名和邮箱' thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) response_dictionary = { 'current': current, 'title': title, 'thirdpartyUser': thirdpartyUser } return render_to_response('settings/change_username_email.html', response_dictionary, context_instance=RequestContext(request))
def thirdparty(request): current = 'thirdparty' title = u'设置 / 第三方' thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) response_dictionary = { 'current': current, 'title': title, 'thirdpartyUser': thirdpartyUser } return render_to_response('settings/thirdparty.html', response_dictionary, context_instance=RequestContext(request))
def profile(request): current = 'profile'; title = u'设置 / 个人信息' thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) userprofileForm = UserprofileForm(instance = request.userprofile) if request.method == 'POST': userprofileForm = UserprofileForm(request.POST, instance = request.userprofile) if userprofileForm.is_valid(): userprofileForm.save() response_dictionary = {'current': current, 'title': title, 'userprofileForm': userprofileForm, 'thirdpartyUser': thirdpartyUser} return render_to_response('settings/profile.html', response_dictionary, context_instance=RequestContext(request))
def change(request): thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) user = None is_user_exist = True is_exist_repo = False username = request.POST.get('username') if username is not None and re.match( "^[a-zA-Z0-9_-]+$", username ) and username != request.user.username and username not in MAIN_NAVS and not username.startswith( '-'): repo_count = RepoManager.count_repo_by_userId(request.user.id) if repo_count > 0: return json_httpResponse({'is_exist_repo': True}) user = GsuserManager.get_user_by_name(username) if user is None: request.user.username = username request.userprofile.username = username request.user.save() request.userprofile.save() for repo in RepoManager.list_repo_by_userId( request.user.id, 0, 100): repo.username = username repo.save() is_user_exist = False goto = '' email = request.POST.get('email') if email is not None and email_re.match(email): user = GsuserManager.get_user_by_email(email) if user is None: Mailer().send_change_email(request.user, email) email_suffix = email.split('@')[-1] if email_suffix in COMMON_EMAIL_DOMAIN: goto = COMMON_EMAIL_DOMAIN[email_suffix] is_user_exist = False if thirdpartyUser is not None: thirdpartyUser.init = 1 thirdpartyUser.save() if username == request.user.username: is_user_exist = False response_dictionary = { 'is_exist_repo': is_exist_repo, 'is_user_exist': is_user_exist, 'goto': goto, 'new_username': username, 'new_email': email } return json_httpResponse(response_dictionary)
def login_github(request): code = request.GET.get('code') if request.GET.get('code') is None: return HttpResponseRedirect('/login/') access_token = github_oauth_access_token(code) if access_token == '': return HttpResponseRedirect('/login/') thirdpartyUser = github_get_thirdpartyUser(access_token) if thirdpartyUser is None or thirdpartyUser.tp_id is None or thirdpartyUser.tp_username is None: return HttpResponseRedirect('/login/') user = github_authenticate(thirdpartyUser) if user is not None: request.session.set_expiry(2592000) user.backend = 'django.contrib.auth.backends.ModelBackend' auth_login(request, user) thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(user.id) if thirdpartyUser.init == 0: return HttpResponseRedirect('/settings/change_username_email/') return HttpResponseRedirect('/dashboard/')
def login_github(request): code = request.GET.get('code') if request.GET.get('code') is None: return HttpResponseRedirect('/login/') access_token = github_oauth_access_token(code) if access_token == '': return HttpResponseRedirect('/login/') thirdpartyUser = github_get_thirdpartyUser(access_token) if thirdpartyUser is None or thirdpartyUser.tp_id is None or thirdpartyUser.tp_username is None: return HttpResponseRedirect('/login/') user = github_authenticate(thirdpartyUser) if user is not None: request.session.set_expiry(2592000) user.backend='django.contrib.auth.backends.ModelBackend' auth_login(request, user) thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(user.id) if thirdpartyUser.init == 0: return HttpResponseRedirect('/settings/change_username_email/') return HttpResponseRedirect('/dashboard/')
def profile(request): current = 'profile' title = u'设置 / 个人信息' thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) userprofileForm = UserprofileForm(instance=request.userprofile) if request.method == 'POST': userprofileForm = UserprofileForm(request.POST, instance=request.userprofile) if userprofileForm.is_valid(): userprofileForm.save() response_dictionary = { 'current': current, 'title': title, 'userprofileForm': userprofileForm, 'thirdpartyUser': thirdpartyUser } return render_to_response('settings/profile.html', response_dictionary, context_instance=RequestContext(request))
def change(request): thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id) user = None is_user_exist = True is_exist_repo = False username = request.POST.get('username') if username is not None and re.match("^[a-zA-Z0-9_-]+$", username) and username != request.user.username and username not in MAIN_NAVS and not username.startswith('-'): repo_count = RepoManager.count_repo_by_userId(request.user.id) if repo_count > 0: return json_httpResponse({'is_exist_repo': True}) user = GsuserManager.get_user_by_name(username) if user is None: request.user.username = username request.userprofile.username = username request.user.save() request.userprofile.save() for repo in RepoManager.list_repo_by_userId(request.user.id, 0, 100): repo.username = username repo.save() is_user_exist = False goto = '' email = request.POST.get('email') if email is not None and email_re.match(email): user = GsuserManager.get_user_by_email(email) if user is None: Mailer().send_change_email(request.user, email) email_suffix = email.split('@')[-1] if email_suffix in COMMON_EMAIL_DOMAIN: goto = COMMON_EMAIL_DOMAIN[email_suffix] is_user_exist = False if thirdpartyUser is not None: thirdpartyUser.init = 1 thirdpartyUser.save() if username == request.user.username: is_user_exist = False response_dictionary = { 'is_exist_repo': is_exist_repo, 'is_user_exist': is_user_exist, 'goto': goto, 'new_username': username, 'new_email': email } return json_httpResponse(response_dictionary)
def login_github_relieve(request): thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_id(request.user.id) if thirdpartyUser_find is not None: thirdpartyUser_find.delete() response_dictionary = {'code': 200, 'result': 'success'} return json_httpResponse(response_dictionary)