25
25
from elisa.core import common
26
26
from elisa.core.utils import defer
27
27
from elisa.core.utils.misc import get_os_name
28
from elisa.core.utils.i18n import get_current_locale
28
29
from elisa.core.media_uri import MediaUri
30
31
from elisa.plugins.account.constants import HTTP_PROTO, API_SERVER, API_VERSION
31
from elisa.plugins.account.models import InstanceModel, ActivityModel
32
from elisa.plugins.account.models import InstanceModel, ActivityModel, \
34
from elisa.plugins.account import resource_provider
195
198
resource_manager = common.application.resource_manager
196
199
return resource_manager.post(MediaUri(uri), model=activity_model)
203
def create_account(email, password):
205
Create a Moovida account for given email address and password. If
206
an account exists for that email address already, the server will
207
return an error and the errback of deferred returned by this
208
function will be fired.
210
@param email: email address of the user
211
@type email: C{unicode}
212
@param password: password requested to protect the account
213
@type password: C{unicode}
214
@return: a deferred fired with the user model returned by the
216
@rtype: L{elisa.core.utils.defer.Deferred}
219
def create_moovida_user(instance_model):
220
provider = resource_provider.get_account_provider()
221
user_model = UserModel()
222
user_model.instances.append(instance_model)
223
user_model.email = email
224
user_model.password = password
226
# username & name would be configurable in profile UI
227
user_model.username = email
228
user_model.name = email
229
user_model.language = get_current_locale()
231
user_model.validated = False
233
uri = '%s://%s/account/%s/user' % (HTTP_PROTO, API_SERVER,
235
resource_manager = common.application.resource_manager
236
return resource_manager.post(MediaUri(uri), model=user_model)
238
# if instance exists already on server, get it
239
dfr = create_instance()
240
dfr.addErrback(lambda failure: get_instance())
241
dfr.addCallback(create_moovida_user)