Beispiel #1
0
def email_password(request):
    if request.method == "POST":
        password = User.objects.make_random_password()
        _data = request.body
        _data = json.loads(_data)
        email = _data['id_email_']
        u = User.objects.get(email=email)
        u.set_password(password)
        u.save()
        emailService = EmailService()

        # email settings
        email_fromaddr = settings.NOTIFICATION['email']['fromaddr']
        email_username = settings.NOTIFICATION['email']['username']
        email_password = settings.NOTIFICATION['email']['password']
        email_mailServer = settings.NOTIFICATION['email']['mailServer']
        emailService.sendEmail(email_fromaddr,
                               email,
                               email_username,
                               email_password,
                               _.EMAIL_USER_PASSWORD_CHANGE,
                               _.EMAIL_USER_PASSWORD_MESSAGE.format(
                                   u.username, password),
                               email_mailServer,
                               html=True)
        json_text = {"status": "success"}
        return HttpResponse(json.dumps(json_text), content_type='text/plain')
Beispiel #2
0
 def send_device_notification_email(self, _active_alert_email,
                                    _email_subject, _email_text):
     emailService = EmailService()
     emailService.sendEmail(email_fromaddr, _active_alert_email,
                            email_username, email_password,
                            _email_subject, _email_text,
                            email_mailServer)
Beispiel #3
0
        def send_device_notification_email(self, _active_alert_email,
                                           _email_subject, _email_text):
            #_email_subject = '#Attention: BEMOSS Device {} has detected a high level of CO2!!!'.format(agent_id)
            # _email_text = 'Here is the detail of device status\n' + str(_tampering_device_msg) \
            #_email_text = 'The CO2 level has exceeded the defined range'
            emailService = EmailService()

            # Send Email
            emailService.sendEmail(email_fromaddr, _active_alert_email,
                                   email_username, email_password,
                                   _email_subject, _email_text,
                                   email_mailServer)
Beispiel #4
0
def approve_users(request):
    if request.method == "POST":
        _data = request.body
        _data = json.loads(_data)
        print _data

        for row in _data['data']:
            user = User.objects.get(id=row[0])
            if row[1] == "true":
                user.is_active = True
            user_group = Group.objects.get(name=row[2].strip())
            if row[3].strip().lower() == 'all':
                user.userprofile.nodes.add(*NodeInfo.objects.all())
            else:
                user.userprofile.nodes.add(
                    NodeInfo.objects.get(node_name=row[3].strip()))
            user.userprofile.save()
            user.groups.add(user_group)
            user.save()
            try:
                emailService = EmailService()
                email_fromaddr = settings.NOTIFICATION['email']['fromaddr']
                email_username = settings.NOTIFICATION['email']['username']
                email_password = settings.NOTIFICATION['email']['password']
                email_mailServer = settings.NOTIFICATION['email']['mailServer']
                _email_subject = _.EMAIL_USER_APPROVED_SUBJECT
                recipient = [user.email]
                text = _.EMAIL_USER_MESSAGE
                new_text = text.format(user.first_name)
                emailService.sendEmail(email_fromaddr,
                                       recipient,
                                       email_username,
                                       email_password,
                                       _email_subject,
                                       new_text,
                                       email_mailServer,
                                       html=True)

            except Exception as er:
                print er

        print "user accounts activated"
        json_text = {"status": "success"}

        return HttpResponse(json.dumps(json_text), content_type='text/plain')
db_database = settings.DATABASES['default']['NAME']
db_host = settings.DATABASES['default']['HOST']
db_port = settings.DATABASES['default']['PORT']
db_user = settings.DATABASES['default']['USER']
db_password = settings.DATABASES['default']['PASSWORD']
db_table_node_device = settings.DATABASES['default']['TABLE_node_device']
db_table_device_info = settings.DATABASES['default']['TABLE_device_info']
db_table_node_info = settings.DATABASES['default']['TABLE_node_info']

multinode_data = db_helper.get_multinode_data()

node_name = multinode_data['this_node']

myips = find_own_ip.getIPs()
_email_subject = node_name+'@'+str(myips[0])
emailService = EmailService()

#email settings
email_fromaddr = settings.NOTIFICATION['email']['fromaddr']
email_recipients = settings.NOTIFICATION['email']['recipients']
email_username = settings.NOTIFICATION['email']['username']
email_password = settings.NOTIFICATION['email']['password']
email_mailServer = settings.NOTIFICATION['email']['mailServer']


smsService = SMSService()
notify_heartbeat = settings.NOTIFICATION['heartbeat']

#Offline variables initialized

platform_table = 'platform_event'
Beispiel #6
0
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User, Group
from django.core.mail import send_mail
from _utils.lockout import LockedOut
from _utils.device_list_utils import get_device_list_and_count
from webapps.buildinginfos.models import Building_Zone
from webapps.multinode.models import NodeInfo, NodeDeviceStatus
from forms import RegistrationForm, RegistrationForm1
import logging
import _utils.messages as _
import json
from django.views.decorators.csrf import ensure_csrf_cookie
from webapps.accounts.models import UserProfile, UserRegistrationRequests
from bemoss_lib.communication.Email import EmailService
import settings
emailservie = EmailService()
logger = logging.getLogger("views")


@ensure_csrf_cookie
def login_user(request):
    print "User login request"
    # Obtain the context for the user's request.
    context = RequestContext(request)

    if request.method == 'POST':
        # Gather the username and password provided by the user.
        # This information is obtained from the login form.
        username = request.POST['username']
        password = request.POST['password']
        user = None