mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Further validation and bugfixes for miningbuddy service
This commit is contained in:
15
settings.py
15
settings.py
@@ -90,6 +90,10 @@ AUTH_PROFILE_MODULE = 'sso.SSOUser'
|
||||
LOGIN_REDIRECT_URL = "/profile"
|
||||
LOGIN_URL = "/login"
|
||||
|
||||
FORCE_SCRIPT_NAME=""
|
||||
DEFAULT_FROM_EMAIL = "bot@auth.dredd.it"
|
||||
ACCOUNT_ACTIVATION_DAYS = 14
|
||||
|
||||
### Jabber Service Settings
|
||||
|
||||
# Vhost to add users to
|
||||
@@ -115,9 +119,14 @@ MUMBLE_SERVER_ID = 1
|
||||
|
||||
### Wiki Service Settings
|
||||
|
||||
# Mediawiki database name
|
||||
WIKI_DATABASE = 'dreddit_wiki'
|
||||
|
||||
FORCE_SCRIPT_NAME=""
|
||||
DEFAULT_FROM_EMAIL = "bot@auth.dredd.it"
|
||||
### Mining Buddy Settings
|
||||
|
||||
# Mining Buddy database name
|
||||
MINING_DATABASE = 'dreddit_mining'
|
||||
|
||||
# Mining buddy secret key (in the config)
|
||||
MINING_SALT = 's98ss7fsc7fd2rf62ctcrlwztstnzve9toezexcsdhfgviuinusxcdtsvbrg'
|
||||
|
||||
ACCOUNT_ACTIVATION_DAYS = 14
|
||||
|
||||
@@ -5,6 +5,7 @@ from django.db import models
|
||||
from django.db.models import signals
|
||||
from django.contrib.auth.models import User, UserManager, Group
|
||||
from eve_api.models import EVEAccount, EVEPlayerCorporation
|
||||
from reddit.models import RedditAccount
|
||||
|
||||
from services import get_api
|
||||
|
||||
@@ -121,9 +122,15 @@ class ServiceAccount(models.Model):
|
||||
# Create a account if we've not got a UID
|
||||
if self.active:
|
||||
if not api.check_user(self.username):
|
||||
eve_api = EVEAccount.objects.filter(user=self.user)
|
||||
eveapi = None
|
||||
for eacc in EVEAccount.objects.filter(user=self.user):
|
||||
if self.character in eacc.characters.all():
|
||||
eveapi = eacc
|
||||
break
|
||||
|
||||
print eveapi
|
||||
reddit = RedditAccount.objects.filter(user=self.user)
|
||||
self.service_uid = api.add_user(self.username, self.password, user=self.user, character=self.character, eveapi=eve_api, reddit=reddit)
|
||||
self.service_uid = api.add_user(self.username, self.password, user=self.user, character=self.character, eveapi=eveapi, reddit=reddit)
|
||||
else:
|
||||
raise ExistingUser('Username %s has already been took' % self.username)
|
||||
else:
|
||||
|
||||
@@ -15,10 +15,10 @@ class MiningBuddyService(BaseService):
|
||||
'provide_login': False }
|
||||
|
||||
|
||||
SQL_ADD_USER = r"INSERT INTO users (username, password, email, emailvalid, confirmed) VALUES (%s, %s, '', 0, 1)"
|
||||
SQL_ADD_USER = r"INSERT INTO users (username, password, email, emailvalid, confirmed) VALUES (%s, %s, %s, 0, 1)"
|
||||
SQL_ADD_API = r"INSERT INTO api_keys (userid, time, apiID, apiKey, api_valid) values (%s, %s, %s, %s, 1)"
|
||||
SQL_DIS_USER = r"UPDATE users SET canLogin = 0 WHERE username = %s"
|
||||
SQL_ENABLE_USER = r"UPDATE users SET canLogin = 1 WHERE username = %s"
|
||||
SQL_ENABLE_USER = r"UPDATE users SET canLogin = 1, password = %s WHERE username = %s"
|
||||
SQL_CHECK_USER = r"SELECT username from users WHERE username = %s and deleted = 0"
|
||||
SQL_DEL_USER = r"UPDATE users set deleted = 1 WHERE username = %s"
|
||||
|
||||
@@ -42,17 +42,22 @@ class MiningBuddyService(BaseService):
|
||||
|
||||
def _gen_mb_hash(self, password, salt=None):
|
||||
if not salt:
|
||||
salt = _gen_salt()
|
||||
salt = self._gen_salt()
|
||||
return crypt.crypt(password, salt)
|
||||
|
||||
def _clean_username(self, username):
|
||||
username = username.strip()
|
||||
return username[0].upper() + username[1:]
|
||||
|
||||
def add_user(self, username, password):
|
||||
def add_user(self, username, password, **kwargs):
|
||||
""" Add a user """
|
||||
pwhash = self._gen_mb_hash(password)
|
||||
self._dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash])
|
||||
if 'user' in kwargs:
|
||||
email = kwargs['user'].email
|
||||
else:
|
||||
email = ''
|
||||
|
||||
self._dbcursor.execute(self.SQL_ADD_USER, [self._clean_username(username), pwhash, email])
|
||||
self._db.connection.commit()
|
||||
return self._clean_username(username)
|
||||
|
||||
@@ -76,7 +81,7 @@ class MiningBuddyService(BaseService):
|
||||
|
||||
def enable_user(self, uid, password):
|
||||
""" Enable a user """
|
||||
pwhash = self._gen_mw_hash(password)
|
||||
pwhash = self._gen_mb_hash(password)
|
||||
self._dbcursor.execute(self.SQL_ENABLE_USER, [pwhash, uid])
|
||||
self._db.connection.commit()
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user