def view_main(request): if request.user.profile.characterid is None: # Not authenticated yet if request.method == 'GET': return direct_to_template( request, 'emauth/main.html', extra_context={'state': 'api_key_form', 'tab': 'auth'}) elif request.method == 'POST': return main_handle_apikey(request) else: if request.user.profile.active: state = 'reauth_form' else: state = 'reactivate_form' # Authenticated, but possibly inactive or outdated if request.method == 'GET': return direct_to_template( request, 'emauth/main.html', extra_context={'state': state, 'tab': 'auth'}) else: profile = request.user.profile profile.active = True profile.save() try: userauth.authenticate_users(request.user) messages.add_message(request, messages.INFO, "Authentication successful.") except userauth.AuthenticationError as e: messages.add_message(request, messages.ERROR, str(e)) return HttpResponseRedirect('/auth/')
def handle(self, *args, **options): userauth.authenticate_users() django.db.close_connection()
def main_handle_apikey(request): profile = request.user.profile keyid = request.POST.get('keyID', None) vcode = request.POST.get('vCode', None) selected_charid = request.POST.get('characterID', None) dorename = request.POST.get('dorename', False) api = apiroot() if vcode is not None and not 'emforum' in vcode: messages.add_message(request, messages.ERROR, "Please change your Verification Code so " "it contains the string 'emforum'") return HttpResponseRedirect('/auth/') try: chars = api.account.Characters(keyID=keyid, vCode=vcode) chars = [(row.name, row.characterID) for row in chars.characters] except Exception as e: messages.add_message(request, messages.ERROR, "Error during API call: %s" % str(e)) return HttpResponseRedirect('/auth/') if len(chars) == 1: charname, charid = chars[0] else: charname = None charid = None for thischarname, thischarid in chars: if (str(thischarid) == selected_charid or thischarname.lower() == profile.mybb_username.lower()): charname = thischarname charid = thischarid break if charname is None: return direct_to_template( request, 'emauth/main.html', extra_context={'state': 'select_character', 'character_list': sorted(chars), 'keyID': keyid, 'vCode': vcode, 'tab': 'auth'}) if charname != profile.mybb_username: if not dorename: return direct_to_template( request, 'emauth/main.html', extra_context={'state': 'ask_rename', 'keyID': keyid, 'vCode': vcode, 'characterID': charid, 'forum_name': profile.mybb_username, 'char_name': charname, 'tab': 'auth'}) else: db = utils.connect('emforum') c = db.cursor() if not userauth.mybb_setusername(c, profile.mybb_uid, charname): db.rollback() messages.add_message(request, messages.ERROR, "That username already exists. Please " "contact a forum administrator to " "resolve this conflict.") return HttpResponseRedirect('/auth/') db.commit() messages.add_message(request, messages.INFO, "Forum username changed to %s" % charname) # Forum username is correct now # Set the profile info charinfo = api.eve.CharacterInfo(characterID=charid) profile.name = charinfo.characterName profile.characterid = charinfo.characterID profile.corp = charinfo.corporation profile.corpid = charinfo.corporationID profile.alliance = getattr(charinfo, 'alliance', None) profile.allianceid = getattr(charinfo, 'allianceID', None) profile.active = True profile.save() try: userauth.authenticate_users(profile.user) messages.add_message(request, messages.INFO, "Authentication successful.") except userauth.AuthenticationError as e: messages.add_message(request, messages.ERROR, str(e)) return HttpResponseRedirect('/auth/')
def handle(self, *args, **options): userauth.authenticate_users()