def update(self, username=None, password=None): if not self.id: return params = dict() if username is not None: params["username"] = username if password is not None: params["password"] = auth.hash(password) if params: self._db.update("user", "id = " + str(self.id), params)
def signup(request): try: user = User.objects.create(username=request.data['username'], password=auth.hash( request.data['password'])) except: return JsonResponse(0, status=417, safe=False) user.save() user = user.toDict() user['authToken'] = auth.getToken(user) return JsonResponse(user, safe=False)
def on_post(self, req, resp): user = req.context['doc'] USER_SCHEMA.validate(user) username = user.pop("username") self.logger.info("Attemted signup with username %s" % username) if self.username_exists(username): self.logger.info("Attemted signup with duplicate username %s" % username) raise falcon.HTTPInvalidParam("username already in use", "username") salt = str(uuid.uuid4()) user.update({ "_id": username, make_private("password_salt"): salt, make_private("encrypted_password"): auth.hash(user.pop("password"), salt) }) resp.body = self.db.save_doc(DB_USER, user)
def create(self): if not self.id: self.id = self._db.insert("user", username=self.username, password=auth.hash(self.password)) return self.id