Skip to content

Commit

Permalink
Rev989, Save users file on newsfeed follow, Local mode in Multiuser p…
Browse files Browse the repository at this point in the history
…lugin to disable restrication and save users data to disk
  • Loading branch information
shortcutme committed Mar 11, 2016
1 parent 0897154 commit ed0e858
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 34 deletions.
1 change: 1 addition & 0 deletions plugins/Newsfeed/NewsfeedPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class UiWebsocketPlugin(object):
def actionFeedFollow(self, to, feeds):
self.user.setFeedFollow(self.site.address, feeds)
self.user.save()
self.response(to, "ok")

def actionFeedListFollow(self, to):
Expand Down
71 changes: 38 additions & 33 deletions plugins/disabled-Multiuser/MultiuserPlugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import re
import sys

from Config import config
from Plugin import PluginManager
from Crypt import CryptBitcoin
import UserPlugin


@PluginManager.registerTo("UiRequest")
Expand Down Expand Up @@ -93,32 +97,6 @@ def getCurrentUser(self):
return user


@PluginManager.registerTo("UserManager")
class UserManagerPlugin(object):
# In multiuser mode do not load the users
def load(self):
if not self.users:
self.users = {}
return self.users

# Find user by master address
# Return: User or None
def get(self, master_address=None):
users = self.list()
if master_address in users:
user = users[master_address]
else:
user = None
return user


@PluginManager.registerTo("User")
class UserPlugin(object):
# In multiuser mode users data only exits in memory, dont write to data/user.json
def save(self):
return False


@PluginManager.registerTo("UiWebsocket")
class UiWebsocketPlugin(object):
# Let the page know we running in multiuser mode
Expand Down Expand Up @@ -148,7 +126,8 @@ def actionUserLogout(self, to):
# Delete from user_manager
user_manager = sys.modules["User.UserManager"].user_manager
if self.user.master_address in user_manager.users:
del user_manager.users[self.user.master_address]
if not config.multiuser_local:
del user_manager.users[self.user.master_address]
self.response(to, "Successful logout")
else:
self.response(to, "User not found")
Expand All @@ -160,7 +139,9 @@ def actionUserLoginForm(self, to):
# Login form submit
def responseUserLogin(self, master_seed):
user_manager = sys.modules["User.UserManager"].user_manager
user = user_manager.create(master_seed=master_seed)
user = user_manager.get(CryptBitcoin.privatekeyToAddress(master_seed))
if not user:
user = user_manager.create(master_seed=master_seed)
if user.master_address:
message = "Successfull login, reloading page..."
message += "<script>document.cookie = 'master_address=%s;path=/;max-age=2592000;'</script>" % user.master_address
Expand All @@ -172,16 +153,40 @@ def responseUserLogin(self, master_seed):

# Disable not Multiuser safe functions
def actionSiteDelete(self, to, *args, **kwargs):
self.cmd("notification", ["info", "This function is disabled on this proxy"])
if not config.multiuser_local:
self.cmd("notification", ["info", "This function is disabled on this proxy"])
else:
return super(UiWebsocketPlugin, self).actionSiteDelete(to, *args, **kwargs)

def actionConfigSet(self, to, *args, **kwargs):
self.cmd("notification", ["info", "This function is disabled on this proxy"])
if not config.multiuser_local:
self.cmd("notification", ["info", "This function is disabled on this proxy"])
else:
return super(UiWebsocketPlugin, self).actionConfigSet(to, *args, **kwargs)

def actionServerShutdown(self, to, *args, **kwargs):
self.cmd("notification", ["info", "This function is disabled on this proxy"])
if not config.multiuser_local:
self.cmd("notification", ["info", "This function is disabled on this proxy"])
else:
return super(UiWebsocketPlugin, self).actionServerShutdown(to, *args, **kwargs)

def actionServerUpdate(self, to, *args, **kwargs):
self.cmd("notification", ["info", "This function is disabled on this proxy"])
if not config.multiuser_local:
self.cmd("notification", ["info", "This function is disabled on this proxy"])
else:
return super(UiWebsocketPlugin, self).actionServerUpdate(to, *args, **kwargs)

def actionSiteClone(self, to, *args, **kwargs):
self.cmd("notification", ["info", "This function is disabled on this proxy"])
if not config.multiuser_local:
self.cmd("notification", ["info", "This function is disabled on this proxy"])
else:
return super(UiWebsocketPlugin, self).actionSiteClone(to, *args, **kwargs)


@PluginManager.registerTo("ConfigPlugin")
class ConfigPlugin(object):
def createArguments(self):
group = self.parser.add_argument_group("Multiuser plugin")
group.add_argument('--multiuser_local', help="Enable unsafe Ui functions and write users to disk", action='store_true')

return super(ConfigPlugin, self).createArguments()
35 changes: 35 additions & 0 deletions plugins/disabled-Multiuser/UserPlugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from Config import config
from Plugin import PluginManager

allow_reload = False

@PluginManager.registerTo("UserManager")
class UserManagerPlugin(object):
def load(self):
if not config.multiuser_local:
# In multiuser mode do not load the users
if not self.users:
self.users = {}
return self.users
else:
return super(UserManagerPlugin, self).load()

# Find user by master address
# Return: User or None
def get(self, master_address=None):
users = self.list()
if master_address in users:
user = users[master_address]
else:
user = None
return user


@PluginManager.registerTo("User")
class UserPlugin(object):
# In multiuser mode users data only exits in memory, dont write to data/user.json
def save(self):
if not config.multiuser_local:
return False
else:
return super(UserPlugin, self).save()
2 changes: 1 addition & 1 deletion src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):

def __init__(self, argv):
self.version = "0.3.6"
self.rev = 986
self.rev = 989
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"
Expand Down

0 comments on commit ed0e858

Please sign in to comment.