Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
9b6eb7a9
Commit
9b6eb7a9
authored
May 31, 2012
by
Sofia Papagiannaki
Browse files
Log main astakos functions
Refs: #2448
parent
c2a57008
Changes
9
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/README
View file @
9b6eb7a9
...
...
@@ -80,6 +80,7 @@ ASTAKOS_RATELIMIT_RETRIES_ALLOWED 3
captcha challenge.
ASTAKOS_EMAILCHANGE_ENABLED False Enable email change mechanism
ASTAKOS_EMAILCHANGE_ACTIVATION_DAYS 10 Number of days that email change requests remain active
ASTAKOS_LOGGING_LEVEL INFO Message logging severity
=================================== ============================================================================= ===========================================================================================
Administrator functions
...
...
snf-astakos-app/astakos/im/forms.py
View file @
9b6eb7a9
...
...
@@ -47,7 +47,9 @@ from django.contrib import messages
from
django.utils.encoding
import
smart_str
from
astakos.im.models
import
AstakosUser
,
Invitation
,
get_latest_terms
,
EmailChange
from
astakos.im.settings
import
INVITATIONS_PER_LEVEL
,
DEFAULT_FROM_EMAIL
,
BASEURL
,
SITENAME
,
RECAPTCHA_PRIVATE_KEY
,
DEFAULT_CONTACT_EMAIL
,
RECAPTCHA_ENABLED
from
astakos.im.settings
import
INVITATIONS_PER_LEVEL
,
DEFAULT_FROM_EMAIL
,
\
BASEURL
,
SITENAME
,
RECAPTCHA_PRIVATE_KEY
,
DEFAULT_CONTACT_EMAIL
,
\
RECAPTCHA_ENABLED
,
LOGGING_LEVEL
from
astakos.im.widgets
import
DummyWidget
,
RecaptchaWidget
from
astakos.im.functions
import
send_change_email
...
...
@@ -143,7 +145,7 @@ class LocalUserCreationForm(UserCreationForm):
user
.
renew_token
()
if
commit
:
user
.
save
()
logger
.
info
(
'Created user %s'
,
user
)
logger
.
_log
(
LOGGING_LEVEL
,
'Created user %s'
%
user
.
email
,
[]
)
return
user
class
InvitedLocalUserCreationForm
(
LocalUserCreationForm
):
...
...
@@ -224,7 +226,7 @@ class ThirdPartyUserCreationForm(forms.ModelForm):
user
.
provider
=
get_query
(
self
.
request
).
get
(
'provider'
)
if
commit
:
user
.
save
()
logger
.
info
(
'Created user %s'
,
user
)
logger
.
_log
(
LOGGING_LEVEL
,
'Created user %s'
%
user
.
email
,
[]
)
return
user
class
InvitedThirdPartyUserCreationForm
(
ThirdPartyUserCreationForm
):
...
...
snf-astakos-app/astakos/im/functions.py
View file @
9b6eb7a9
...
...
@@ -40,17 +40,40 @@ from django.core.mail import send_mail
from
django.core.urlresolvers
import
reverse
from
django.core.exceptions
import
ValidationError
from
django.template
import
Context
,
loader
from
django.contrib.auth
import
login
as
auth_login
,
logout
as
auth_logout
from
django.http
import
HttpRequest
from
urllib
import
quote
from
urlparse
import
urljoin
from
smtplib
import
SMTPException
from
datetime
import
datetime
from
functools
import
wraps
from
astakos.im.settings
import
DEFAULT_CONTACT_EMAIL
,
DEFAULT_FROM_EMAIL
,
SITENAME
,
BASEURL
,
DEFAULT_ADMIN_EMAIL
from
astakos.im.settings
import
DEFAULT_CONTACT_EMAIL
,
DEFAULT_FROM_EMAIL
,
\
SITENAME
,
BASEURL
,
DEFAULT_ADMIN_EMAIL
,
LOGGING_LEVEL
from
astakos.im.models
import
Invitation
,
AstakosUser
logger
=
logging
.
getLogger
(
__name__
)
def
logged
(
func
,
msg
):
@
wraps
(
func
)
def
with_logging
(
*
args
,
**
kwargs
):
email
=
''
user
=
None
if
len
(
args
)
==
2
and
isinstance
(
args
[
1
],
AstakosUser
):
user
=
args
[
1
]
elif
len
(
args
)
==
1
and
isinstance
(
args
[
0
],
HttpRequest
):
request
=
args
[
0
]
user
=
request
.
user
email
=
user
.
email
if
user
and
user
.
is_authenticated
()
else
''
r
=
func
(
*
args
,
**
kwargs
)
logger
.
_log
(
LOGGING_LEVEL
,
msg
%
email
,
[])
return
r
return
with_logging
login
=
logged
(
auth_login
,
'%s logged in.'
)
logout
=
logged
(
auth_logout
,
'%s logged out.'
)
def
send_verification
(
user
,
template_name
=
'im/activation_email.txt'
):
"""
Send email to user to verify his/her email and activate his/her account.
...
...
@@ -73,7 +96,8 @@ def send_verification(user, template_name='im/activation_email.txt'):
logger
.
exception
(
e
)
raise
SendVerificationError
()
else
:
logger
.
info
(
'Sent activation %s'
,
user
)
msg
=
'Sent activation %s'
%
user
.
email
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
send_activation
(
user
,
template_name
=
'im/activation_email.txt'
):
send_verification
(
user
,
template_name
)
...
...
@@ -100,7 +124,8 @@ def send_admin_notification(user, template_name='im/admin_notification.txt'):
logger
.
exception
(
e
)
raise
SendNotificationError
()
else
:
logger
.
info
(
'Sent admin notification for user %s'
,
user
)
msg
=
'Sent admin notification for user %s'
%
user
.
email
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
send_invitation
(
invitation
,
template_name
=
'im/invitation.txt'
):
"""
...
...
@@ -123,7 +148,8 @@ def send_invitation(invitation, template_name='im/invitation.txt'):
logger
.
exception
(
e
)
raise
SendInvitationError
()
else
:
logger
.
info
(
'Sent invitation %s'
,
invitation
)
msg
=
'Sent invitation %s'
%
invitation
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
send_greeting
(
user
,
email_template_name
=
'im/welcome_email.txt'
):
"""
...
...
@@ -145,7 +171,8 @@ def send_greeting(user, email_template_name='im/welcome_email.txt'):
logger
.
exception
(
e
)
raise
SendGreetingError
()
else
:
logger
.
info
(
'Sent greeting %s'
,
user
)
msg
=
'Sent greeting %s'
%
user
.
email
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
send_feedback
(
msg
,
data
,
user
,
email_template_name
=
'im/feedback_mail.txt'
):
subject
=
_
(
"Feedback from %s alpha2 testing"
%
SITENAME
)
...
...
@@ -161,7 +188,8 @@ def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
logger
.
exception
(
e
)
raise
SendFeedbackError
()
else
:
logger
.
info
(
'Sent feedback from %s'
,
user
.
email
)
msg
=
'Sent feedback from %s'
%
user
.
email
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
send_change_email
(
ec
,
request
,
email_template_name
=
'registration/email_change_email.txt'
):
try
:
...
...
@@ -177,7 +205,8 @@ def send_change_email(ec, request, email_template_name='registration/email_chang
logger
.
exception
(
e
)
raise
ChangeEmailError
()
else
:
logger
.
info
(
'Sent change email for %s'
,
ec
.
user
.
email
)
msg
=
'Sent change email for %s'
%
ec
.
user
.
email
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
activate
(
user
,
email_template_name
=
'im/welcome_email.txt'
):
"""
...
...
snf-astakos-app/astakos/im/middleware.py
View file @
9b6eb7a9
...
...
@@ -32,10 +32,11 @@
# or implied, of GRNET S.A.
from
urllib
import
unquote
from
django.contrib.auth
import
authenticate
,
login
from
django.contrib.auth
import
authenticate
from
astakos.im.settings
import
COOKIE_NAME
from
astakos.im.models
import
AstakosUser
from
astakos.im.functions
import
login
class
CookieAuthenticationMiddleware
(
object
):
def
process_request
(
self
,
request
):
...
...
snf-astakos-app/astakos/im/models.py
View file @
9b6eb7a9
...
...
@@ -52,8 +52,8 @@ from django.db import transaction
from
django.db.models.signals
import
post_save
,
post_syncdb
from
astakos.im.settings
import
DEFAULT_USER_LEVEL
,
INVITATIONS_PER_LEVEL
,
\
AUTH_TOKEN_DURATION
,
BILLING_FIELDS
,
QUEUE_CONNECTION
,
SITENAME
,
\
EMAILCHANGE_ACTIVATION_DAYS
AUTH_TOKEN_DURATION
,
BILLING_FIELDS
,
QUEUE_CONNECTION
,
SITENAME
,
\
EMAILCHANGE_ACTIVATION_DAYS
,
LOGGING_LEVEL
QUEUE_CLIENT_ID
=
3
# Astakos.
...
...
@@ -170,6 +170,8 @@ class AstakosUser(User):
self
.
auth_token_created
=
datetime
.
now
()
self
.
auth_token_expires
=
self
.
auth_token_created
+
\
timedelta
(
hours
=
AUTH_TOKEN_DURATION
)
msg
=
'Token renewed for %s'
%
self
.
email
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
def
__unicode__
(
self
):
return
self
.
username
...
...
snf-astakos-app/astakos/im/settings.py
View file @
9b6eb7a9
...
...
@@ -82,3 +82,7 @@ EMAILCHANGE_ENABLED = getattr(settings, 'ASTAKOS_EMAILCHANGE_ENABLED', False)
# Set the expiration time (in days) of email change requests
EMAILCHANGE_ACTIVATION_DAYS
=
getattr
(
settings
,
'ASTAKOS_EMAILCHANGE_ACTIVATION_DAYS'
,
10
)
# Set the astakos message logging severity
from
logging
import
INFO
LOGGING_LEVEL
=
getattr
(
settings
,
'ASTAKOS_LOGGING_LEVEL'
,
INFO
)
\ No newline at end of file
snf-astakos-app/astakos/im/target/redirect.py
View file @
9b6eb7a9
...
...
@@ -36,7 +36,7 @@ from django.shortcuts import redirect
from
django.utils.translation
import
ugettext
as
_
from
django.contrib
import
messages
from
django.utils.http
import
urlencode
from
django.contrib.auth
import
login
as
auth_login
,
authenticate
,
logout
from
django.contrib.auth
import
authenticate
from
django.http
import
HttpResponse
,
HttpResponseBadRequest
from
django.core.exceptions
import
ValidationError
...
...
@@ -45,6 +45,7 @@ from urlparse import urlunsplit, urlsplit, urlparse, parse_qsl
from
astakos.im.settings
import
COOKIE_NAME
,
COOKIE_DOMAIN
from
astakos.im.util
import
set_cookie
from
astakos.im.functions
import
login
as
auth_login
,
logout
import
logging
...
...
snf-astakos-app/astakos/im/util.py
View file @
9b6eb7a9
...
...
@@ -37,18 +37,19 @@ import time
from
urllib
import
quote
from
urlparse
import
urlsplit
,
urlunsplit
from
functools
import
wraps
from
datetime
import
tzinfo
,
timedelta
from
django.http
import
HttpResponse
,
HttpResponseBadRequest
,
urlencode
from
django.template
import
RequestContext
from
django.utils.translation
import
ugettext
as
_
from
django.contrib.auth
import
login
,
authenticate
from
django.contrib.auth
import
authenticate
from
django.core.urlresolvers
import
reverse
from
django.core.exceptions
import
ValidationError
from
astakos.im.models
import
AstakosUser
,
Invitation
,
ApprovalTerms
from
astakos.im.settings
import
INVITATIONS_PER_LEVEL
,
COOKIE_NAME
,
COOKIE_DOMAIN
,
COOKIE_SECURE
,
FORCE_PROFILE_UPDATE
from
astakos.im.settings
import
INVITATIONS_PER_LEVEL
,
COOKIE_NAME
,
\
COOKIE_DOMAIN
,
COOKIE_SECURE
,
FORCE_PROFILE_UPDATE
,
LOGGING_LEVEL
from
astakos.im.functions
import
login
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -141,6 +142,8 @@ def set_cookie(response, user):
response
.
set_cookie
(
COOKIE_NAME
,
value
=
cookie_value
,
expires
=
expire_fmt
,
path
=
'/'
,
domain
=
COOKIE_DOMAIN
,
secure
=
COOKIE_SECURE
)
msg
=
'Cookie [expiring %s] set for %s'
%
(
user
.
auth_token_expires
,
user
.
email
)
logger
.
_log
(
LOGGING_LEVEL
,
msg
,
[])
class
lazy_string
(
object
):
def
__init__
(
self
,
function
,
*
args
,
**
kwargs
):
...
...
snf-astakos-app/astakos/im/views.py
View file @
9b6eb7a9
...
...
@@ -47,7 +47,6 @@ from django.core.urlresolvers import reverse
from
django.contrib.auth.decorators
import
login_required
from
django.contrib
import
messages
from
django.db
import
transaction
from
django.contrib.auth
import
logout
as
auth_logout
from
django.utils.http
import
urlencode
from
django.http
import
HttpResponseRedirect
,
HttpResponseBadRequest
from
django.db.utils
import
IntegrityError
...
...
@@ -58,9 +57,9 @@ from astakos.im.models import AstakosUser, Invitation, ApprovalTerms
from
astakos.im.activation_backends
import
get_backend
,
SimpleBackend
from
astakos.im.util
import
get_context
,
prepare_response
,
set_cookie
,
get_query
from
astakos.im.forms
import
*
from
astakos.im.functions
import
send_greeting
,
send_feedback
,
SendMailError
from
astakos.im.functions
import
send_greeting
,
send_feedback
,
SendMailError
,
\
invite
as
invite_func
,
logout
as
auth_logout
from
astakos.im.settings
import
DEFAULT_CONTACT_EMAIL
,
DEFAULT_FROM_EMAIL
,
COOKIE_NAME
,
COOKIE_DOMAIN
,
IM_MODULES
,
SITENAME
,
LOGOUT_NEXT
from
astakos.im.functions
import
invite
as
invite_func
logger
=
logging
.
getLogger
(
__name__
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment