Commits

Matthew Marshall  committed 09e7fcb

Added code for writing to a htpasswd file.

  • Participants
  • Parent commits aef38c4

Comments (0)

Files changed (3)

File htpasswdutils.py

+import anydbm, crypt, random, os, os.path
+
+from freehg.repos.models import Repo
+from django.contrib.auth.models import User
+
+from django.conf import settings
+
+
+def update_password(username, password):
+    alphabeta = "./abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    salt = random.choice(alphabeta)+random.choice(alphabeta)
+    crypted = crypt.crypt(password, salt)
+
+    db = anydbm.open(settings.PASSWORD_DBM_FILE, 'c')
+    db[str(username)] = crypted+":hguser"
+    db.close()
+
+def monkeypatch_user_model():
+    _old_set_password = User.set_password
+    def set_password(self, raw_password):
+        update_password(self.username, raw_password)
+        _old_set_password(self, raw_password)
+    User.set_password = set_password

File repos/views.py

         repo.save()
         request.user.message_set.create(message=
                 "Repository '%s' created." % repo.name)
-        return HttpResponseRedirect('/')
+        return HttpResponseRedirect(repo.get_absolute_url())
 
     return render_to_response('frontpage.html',
         dict(
     # Uncomment this for admin:
     (r'^admin/', include('django.contrib.admin.urls')),
 )
+
+from freehg.htpasswdutils import monkeypatch_user_model
+monkeypatch_user_model()