~moovida-developers/moovida/account

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/account/utils.py

  • Committer: Philippe Normand
  • Date: 2009-09-15 16:41:29 UTC
  • mfrom: (1498.5.57 account_creation)
  • Revision ID: philippe@fluendo.com-20090915164129-9fwrd3vg84hvdjk8
new_account controllers refactored

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
29
30
 
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, \
 
33
     UserModel
 
34
from elisa.plugins.account import resource_provider
32
35
 
33
36
import platform
34
37
 
195
198
    resource_manager = common.application.resource_manager
196
199
    return resource_manager.post(MediaUri(uri), model=activity_model)
197
200
 
 
201
 
 
202
 
 
203
def create_account(email, password):
 
204
    """
 
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.
 
209
 
 
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
 
215
                     server
 
216
    @rtype:          L{elisa.core.utils.defer.Deferred}
 
217
    """
 
218
 
 
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
 
225
 
 
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()
 
230
        user_model.step = 0
 
231
        user_model.validated = False
 
232
 
 
233
        uri = '%s://%s/account/%s/user' % (HTTP_PROTO, API_SERVER,
 
234
                                           API_VERSION)
 
235
        resource_manager = common.application.resource_manager
 
236
        return resource_manager.post(MediaUri(uri), model=user_model)
 
237
 
 
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)
 
242
    return dfr