1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
from lazr.restful.frameworks.django import IDjangoLocation
5
from lazr.restful.declarations import (export_as_webservice_entry,
6
collection_default_content, exported, export_write_operation,
7
export_as_webservice_collection, operation_parameters,
9
from zope.schema import Text, TextLine, List
23
class IAccount(IDjangoLocation):
24
export_as_webservice_entry()
25
id = exported(Text(title=u"Account ID"))
26
preferred_email = exported(Text(title=u"Primary email address"))
27
verified_emails = exported(List(title=u"List of verified emails",
29
unverified_emails = exported(List(value_type=Text(),
30
title=u"List of unverified emails"))
33
class IRegistration(IAccount):
34
export_as_webservice_entry()
37
class IValidation(IAccount):
38
export_as_webservice_entry()
41
class IAuthentication(IAccount):
42
export_as_webservice_entry()
45
class ICaptcha(IDjangoLocation):
46
export_as_webservice_entry()
47
id = exported(Text(title=u"Captcha ID"))
48
content = exported(Text(title=u"Captcha content"))
51
class IAccountSet(IDjangoLocation):
52
export_as_webservice_collection(IAccount)
54
@collection_default_content()
56
"""Fail, as no default content should be provided."""
58
def get(request, unique_id):
59
"""Retrieve a account by its ID."""
61
@export_read_operation()
63
""" Get details for the currently authenticated user. """
65
@operation_parameters(
66
team_names=List(title=u"List of team names to check",
69
@export_read_operation()
70
def team_memberships(team_names):
71
"""Query account for team memberships"""
73
@operation_parameters(
74
email_token=TextLine(title=u"Email validation token."))
75
@export_read_operation()
76
def validate_email(email_token):
77
"""Validate email by sending token user received in email"""
80
class IAuthenticationSet(IAccountSet):
81
export_as_webservice_collection(IAuthentication)
83
@collection_default_content()
85
"""Fail, as no default content should be provided."""
87
@operation_parameters(
88
token_name=TextLine(title=u"Token name."))
89
@export_read_operation()
90
def authenticate(token_name):
91
"""Obtain OAuth token for logged in user"""
93
@operation_parameters(
94
consumer_key=TextLine(title=u"User's OpenID identifier"))
95
@export_read_operation()
96
def list_tokens(consumer_key):
97
""" Get the currently valid tokens for a given user """
99
@operation_parameters(
100
token=TextLine(title=u"The token you want to validate"),
101
consumer_key=TextLine(title=u"The consumer key (openid identifier)")
103
@export_read_operation()
104
def validate_token(token, consumer_key):
105
"""Check that a token is valid.
107
If valid, this method return the token and consumer secrets
110
@operation_parameters(
111
token=TextLine(title=u"The token you want to invalidate"),
112
consumer_key=TextLine(title=u"The consumer key (openid identifier)")
114
@export_write_operation()
115
def invalidate_token(token, consumer_key):
116
""" Make the given token invalid """
118
@operation_parameters(
119
team_names=List(title=u"List of team names to check",
121
openid_identifier=Text(title=u"OpenID Identifier used for asking for"
122
u"team memberships on behalf of other user.")
124
@export_read_operation()
125
def team_memberships(team_names, openid_identifier):
126
"""Query user for team memberships"""
129
class IValidationSet(IAccountSet):
133
class IRegistrationSet(IAccountSet):
134
export_as_webservice_collection(IRegistration)
136
@collection_default_content()
138
"""Fail, as no default content should be provided."""
140
@operation_parameters(
141
email=TextLine(title=u"Email address."),
142
password=TextLine(title=u"Password should be at least 8 "
143
"characters long and contain at least one uppercase letter "
145
captcha_id=TextLine(title=u"ID for the generated captcha"),
146
captcha_solution=TextLine(title=u"Solution for the generated "
148
@export_write_operation()
149
def register(email, password, captcha_id, captcha_solution):
150
""" Generate a new captcha """
153
class ICaptchaSet(IDjangoLocation):
154
export_as_webservice_collection(ICaptcha)
156
@collection_default_content()
158
"""Fail, as no default content should be provided."""
160
def get(request, unique_id):
161
"""Retrieve a captcha by its ID."""
163
@export_write_operation()
165
""" Generate a new captcha """