# HG changeset patch
# User Marcin Kuzminski
# Date 2011-03-05 23:06:28
# Node ID 716911af91e17c04e625dbfa3db20475ae271a88
# Parent fcb5054937f693bb31efe5ae70c3126078283b5f
Added api_key into user, api key get's generated again after password change
updated ini files
diff --git a/development.ini b/development.ini
--- a/development.ini
+++ b/development.ini
@@ -32,7 +32,7 @@ threadpool_workers = 5
threadpool_max_requests = 6
##option to use threads of process
-use_threadpool = false
+use_threadpool = true
use = egg:Paste#http
host = 0.0.0.0
diff --git a/production.ini b/production.ini
--- a/production.ini
+++ b/production.ini
@@ -29,7 +29,7 @@ debug = true
threadpool_workers = 5
##max request before thread respawn
-threadpool_max_requests = 2
+threadpool_max_requests = 6
##option to use threads of process
use_threadpool = true
@@ -47,7 +47,7 @@ cache_dir = %(here)s/data
index_dir = %(here)s/data/index
cut_off_limit = 256000
force_https = false
-commit_parse_limit = 250
+commit_parse_limit = 25
use_gravatar = true
####################################
@@ -94,7 +94,6 @@ beaker.cache.short_term.expire=60
beaker.cache.long_term.type=memory
beaker.cache.long_term.expire=36000
-
beaker.cache.sql_cache_short.type=memory
beaker.cache.sql_cache_short.expire=10
@@ -141,7 +140,8 @@ logview.pylons.util = #eee
#########################################################
### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ###
#########################################################
-sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
+#sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
+sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
#sqlalchemy.db1.echo = False
#sqlalchemy.db1.pool_recycle = 3600
sqlalchemy.convert_unicode = true
diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py
--- a/rhodecode/lib/__init__.py
+++ b/rhodecode/lib/__init__.py
@@ -27,3 +27,12 @@
def str2bool(v):
return v.lower() in ["yes", "true", "t", "1"] if v else None
+
+def generate_api_key(username, salt=None):
+ from tempfile import _RandomNameSequence
+ import hashlib
+
+ if salt is None:
+ salt = _RandomNameSequence().next()
+
+ return hashlib.sha1(username + salt).hexdigest()
diff --git a/rhodecode/lib/auth.py b/rhodecode/lib/auth.py
--- a/rhodecode/lib/auth.py
+++ b/rhodecode/lib/auth.py
@@ -28,7 +28,8 @@ import bcrypt
import random
import logging
import traceback
-
+import hashlib
+from tempfile import _RandomNameSequence
from decorator import decorator
from pylons import config, session, url, request
@@ -87,6 +88,12 @@ def get_crypt_password(password):
"""
return bcrypt.hashpw(password, bcrypt.gensalt(10))
+def generate_api_key(username, salt=None):
+ if salt is None:
+ salt = _RandomNameSequence().next()
+
+ return hashlib.sha1(username + salt).hexdigest()
+
def check_password(password, hashed):
return bcrypt.hashpw(password, hashed) == hashed
diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py
--- a/rhodecode/lib/celerylib/tasks.py
+++ b/rhodecode/lib/celerylib/tasks.py
@@ -245,6 +245,7 @@ def reset_user_password(user_email):
auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
if user:
user.password = auth.get_crypt_password(new_passwd)
+ user.api_key = auth.generate_api_key(user.username)
sa.add(user)
sa.commit()
log.info('change password for %s', user_email)
diff --git a/rhodecode/lib/db_manage.py b/rhodecode/lib/db_manage.py
--- a/rhodecode/lib/db_manage.py
+++ b/rhodecode/lib/db_manage.py
@@ -35,7 +35,7 @@ from os.path import dirname as dn, join
from rhodecode import __dbversion__
from rhodecode.model import meta
-from rhodecode.lib.auth import get_crypt_password
+from rhodecode.lib.auth import get_crypt_password, generate_api_key
from rhodecode.lib.utils import ask_ok
from rhodecode.model import init_model
from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
@@ -442,6 +442,7 @@ class DbManage(object):
new_user = User()
new_user.username = username
new_user.password = get_crypt_password(password)
+ new_user.api_key = generate_api_key(username)
new_user.name = 'RhodeCode'
new_user.lastname = 'Admin'
new_user.email = email
@@ -461,6 +462,7 @@ class DbManage(object):
def_user = User()
def_user.username = 'default'
def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
+ def_user.api_key = generate_api_key('default')
def_user.name = 'Anonymous'
def_user.lastname = 'User'
def_user.email = 'anonymous@rhodecode.org'
@@ -484,8 +486,8 @@ class DbManage(object):
('hg.create.repository', 'Repository create'),
('hg.create.none', 'Repository creation disabled'),
('hg.register.none', 'Register disabled'),
- ('hg.register.manual_activate', 'Register new user with rhodecode without manual activation'),
- ('hg.register.auto_activate', 'Register new user with rhodecode without auto activation'),
+ ('hg.register.manual_activate', 'Register new user with RhodeCode without manual activation'),
+ ('hg.register.auto_activate', 'Register new user with RhodeCode without auto activation'),
]
for p in perms:
diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py
--- a/rhodecode/model/user.py
+++ b/rhodecode/model/user.py
@@ -37,6 +37,7 @@ from rhodecode.model.db import User
from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException
from sqlalchemy.exc import DatabaseError
+from rhodecode.lib import generate_api_key
log = logging.getLogger(__name__)
@@ -68,6 +69,7 @@ class UserModel(BaseModel):
for k, v in form_data.items():
setattr(new_user, k, v)
+ new_user.api_key = generate_api_key(form_data['username'])
self.sa.add(new_user)
self.sa.commit()
except:
@@ -91,6 +93,7 @@ class UserModel(BaseModel):
new_user = User()
new_user.username = username.lower() # add ldap account always lowercase
new_user.password = get_crypt_password(password)
+ new_user.api_key = generate_api_key(username)
new_user.email = attrs['email']
new_user.active = True
new_user.ldap_dn = user_dn
@@ -134,19 +137,20 @@ class UserModel(BaseModel):
def update(self, user_id, form_data):
try:
- new_user = self.get(user_id, cache=False)
- if new_user.username == 'default':
+ user = self.get(user_id, cache=False)
+ if user.username == 'default':
raise DefaultUserException(
_("You can't Edit this user since it's"
" crucial for entire application"))
for k, v in form_data.items():
if k == 'new_password' and v != '':
- new_user.password = v
+ user.password = v
+ user.api_key = generate_api_key(user.username)
else:
- setattr(new_user, k, v)
+ setattr(user, k, v)
- self.sa.add(new_user)
+ self.sa.add(user)
self.sa.commit()
except:
log.error(traceback.format_exc())
@@ -155,19 +159,20 @@ class UserModel(BaseModel):
def update_my_account(self, user_id, form_data):
try:
- new_user = self.get(user_id, cache=False)
- if new_user.username == 'default':
+ user = self.get(user_id, cache=False)
+ if user.username == 'default':
raise DefaultUserException(
_("You can't Edit this user since it's"
" crucial for entire application"))
for k, v in form_data.items():
if k == 'new_password' and v != '':
- new_user.password = v
+ user.password = v
+ user.api_key = generate_api_key(user.username)
else:
if k not in ['admin', 'active']:
- setattr(new_user, k, v)
+ setattr(user, k, v)
- self.sa.add(new_user)
+ self.sa.add(user)
self.sa.commit()
except:
log.error(traceback.format_exc())
diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css
--- a/rhodecode/public/css/style.css
+++ b/rhodecode/public/css/style.css
@@ -858,7 +858,7 @@ padding:0 0 8px;
padding:0 0 8px !important;
}
-#content div.box div.form div.fields div.field div.label label {
+#content div.box div.form div.fields div.field div.label label, div.label label{
color:#393939;
font-weight:700;
}
diff --git a/rhodecode/templates/admin/users/user_edit.html b/rhodecode/templates/admin/users/user_edit.html
--- a/rhodecode/templates/admin/users/user_edit.html
+++ b/rhodecode/templates/admin/users/user_edit.html
@@ -26,19 +26,23 @@
${h.form(url('user', id=c.user.user_id),method='put')}
%def>
diff --git a/rhodecode/templates/admin/users/user_edit_my_account.html b/rhodecode/templates/admin/users/user_edit_my_account.html
--- a/rhodecode/templates/admin/users/user_edit_my_account.html
+++ b/rhodecode/templates/admin/users/user_edit_my_account.html
@@ -34,7 +34,11 @@
-
+
+
+ ${c.user.api_key}
+
+