Permalink
Browse files

keep charts after deleting a user

  • Loading branch information...
1 parent c6437a6 commit 5f0c4b22aa26a2fd8aca2a4ef6a9f5bf098573b7 @gka gka committed Aug 19, 2012
Showing with 20 additions and 12 deletions.
  1. +1 −1 lib/api/auth.php
  2. +1 −11 lib/api/users.php
  3. +18 −0 lib/core/build/classes/datawrapper/User.php
View
@@ -23,7 +23,7 @@
$payload = json_decode($app->request()->getBody());
if (time() - $payload->time < 3000) {
$user = UserQuery::create()->findOneByEmail($payload->email);
- if (!empty($user)) {
+ if (!empty($user) && $user->getDeleted() == false) {
$hash = hash_hmac('sha256', $user->getPwd(), $payload->time);
if ($hash === $payload->pwhash) {
DatawrapperSession::login($user);
View
@@ -167,18 +167,8 @@ function email_exists($email) {
if (!empty($user)) {
if ($user->getPwd() == $payload->pwd) {
- // Delete all charts
- ChartQuery::create()
- ->findByUser($user)
- ->delete();
-
- // Delete user actions from log
- ActionQuery::create()
- ->findByUser($user)
- ->delete();
-
// Delete user
- $user->delete();
+ $user->erase();
ok();
} else {
@@ -39,4 +39,22 @@ public function hasCharts() {
return count(ChartQuery::create()->getPublicChartsByUser($this)) > 0;
}
+ /*
+ * this deletes all information stored by the user and
+ * makes it impossible to login again
+ */
+ public function erase() {
+ $u = $this;
+ $u->setEmail('DELETED');
+ $u->setName('');
+ $u->setWebsite('');
+ $u->setSmProfile('');
+ $u->setActivateToken('');
+ $u->setResetPasswordToken('');
+ $u->setPwd('');
+ $u->setRole('guest');
+ $u->setDeleted(true);
+ $u->save();
+ }
+
} // User

0 comments on commit 5f0c4b2

Please sign in to comment.