Exemplo n.º 1
0
 def handle(self, request, data):
     email = data.get("email")
     try:
         res = keystoneapi.get_user(email)
         if not (res.get("success") or res.get("result")):
             return None                
         user = res.get("result")
         user_id = user.get('id')
         email_activation_code = generate_sms_activation_code()
         data = {"email_activation_code": email_activation_code,
                 "email_activation_code_time": timeutils.strtime()}
         # email confirmation about the change
         send_templated_email("JioCloud account password change confirmation",
             [email],
             html_template="signup/password_change_verification.html",
             template_context={
             "name": user.get("first_name") if user.get("first_name") else user.get("name"),
             "reset_password_path": reverse_lazy('horizon_jiocloud:resetPassword', kwargs={'user_id':user_id, 'code':email_activation_code}),
             "SITE_URL": getattr(settings, "SITE_URL", "http://127.0.0.1"),
             })
         # push changes to keystone database
         response = keystoneapi.update_user(user_id, data)
     except Exception as e:
         LOG.exception(e)
     return render_to_response('signup/forgot_password_success.html', 
             {'email':settings.DEFAULT_FROM_EMAIL, 'user_id': user_id})
Exemplo n.º 2
0
def resendSms(request, user_id):
     url = reverse_lazy('horizon_jiocloud:user_sms_activation',
                        kwargs={'user_id':user_id})
     # This method serves re-sending SMS multiple times 
     # to cater to SMS sending failures.
     # If the OTP is expired, a new one will be generated
     try:
         res = keystoneapi.get_user(user_id)
         if not (res.get("success") or res.get("result")):
             raise Exception('Unable to get user details')
     except Exception as e:
         LOG.exception(e)
         return http.HttpResponseRedirect(url + "?resentSms=True&resentSuccess=False")
     user = res.get("result")
     phone = user.get("phone")
     sms_activation_code = user.get("sms_activation_code")
     sms_activation_code_time = user.get("sms_activation_code_time")
     try:
         if is_sms_expired(sms_activation_code_time):
             sms_activation_code = generate_sms_activation_code()
             data = {"sms_activation_code": sms_activation_code,
                     "sms_activation_code_time": timeutils.strtime()}
             # push changes to keystone database
             response = keystoneapi.update_user(user_id, data)
         generate_and_send_sms(phone, sms_activation_code)
     except Exception as e:
         LOG.exception(e)
         return http.HttpResponseRedirect(url + "?resentSms=True&resentSuccess=False")
     return http.HttpResponseRedirect(url + "?resentSms=True&resentSuccess=True")
Exemplo n.º 3
0
    def handle(self, request, data):
        phone = data.get("phone")
        request.session["phone"] = phone
        if not self.fields.has_key("sms_activation_code"):
            # No "sms_activation_code" field in form
            # So generate OTP to start phone number change process;
            # send SMS containing the OTP and store OTP details
            # in database for later verification
            sms_activation_code = generate_sms_activation_code()
            data = {"sms_activation_code": sms_activation_code,
                    "sms_activation_code_time": timeutils.strtime()}
            try:
                generate_and_send_sms(phone, sms_activation_code)
                messages.success(request,
                                 'Please enter the SMS code to change phone number')
            except Exception as ex:
                LOG.exception(ex)
                self.set_non_field_errors([
                        self.get_default_error_message()
                    ])
                return None
        else:
            # check if the code submitted in the form and that in the 
            # database match
            code = data.get("sms_activation_code")
            sms_activation_code = self.user.get("sms_activation_code")
            if sms_activation_code not in [code]:
                self.set_non_field_errors(["Invalid Activation Code"])
                return None
            # codes matched. so we will change the phone number
            # in database.
            # sms_activation_code no more required so unset it
            # in database.
            data["sms_activation_code"] = ""
            request.session["phone"] = ""
            try:
                # email confirmation about the change
                send_templated_email("JioCloud account phone number changed",
                    [self.user.get("email")],
                    html_template="change_phone/phone_change_cofirmation_email.html",
                    template_context={
                    "name": self.user.get("first_name") if self.user.get("first_name") else self.user.get("name"),
                    "phone": phone,
                    })
                messages.success(request,
                                 'Phone number has been updated successfully.')
            except Exception as ex:
                LOG.exception(ex)

        try:
            # push changes to keystone database
            response = keystoneapi.update_user(self.request.user.id, data)
        except Exception:
            response = exceptions.handle(request, ignore=True)
            messages.error(request, 'Unable to change phone number.')

        return shortcuts.redirect(request.build_absolute_uri())
Exemplo n.º 4
0
    def handle(self, request, data):
        new_email = data.get("email")
        email_activation_code = generate_sms_activation_code()
        data = {"email_activation_code": email_activation_code,
                "email_activation_code_time": timeutils.strtime()}
        try:
            # email confirmation about the change
            send_templated_email("JioCloud account email change confirmation",
                [new_email],
                html_template="change_email/email_change_verification.html",
                template_context={
                "name": self.user.get("first_name") if self.user.get("first_name") else self.user.get("name"),
                "email_activation_path": reverse('horizon:settings:email:index') + 'activate/' + email_activation_code + '?email=' + new_email,
                })
            # push changes to keystone database
            response = keystoneapi.update_user(self.request.user.id, data)
            messages.success(request,
                             'Please click the link sent to your new email to activate it')
        except Exception as ex:
            LOG.exception(ex)
            response = exceptions.handle(request, ignore=True)
            messages.error(request, 'Unable to change email.')

        return shortcuts.redirect(request.build_absolute_uri())
Exemplo n.º 5
0
    def handle(self, request, data):
        res = {}
        user_id = None
        password = data.get("password")
        email = data.get("email")
        first_name = data.get("first_name")
        # last_name = data.get("last_name")
        # company = data.get("company")
        # address = data.get("address")
        # country_code = data.get("country_code")
        # country = data.get("country")
        # country_list = self.get_country(country)
        # if country_list:
        #     country_name = country_list[0].name_ascii
        # state = data.get("state")
        # state_list = self.get_state(state)
        # if state_list:
        #     state_name = state_list[0].name_ascii
        # city = data.get("city")
        # city_list = self.get_city(city)
        # if city_list:
        #     city_name = city_list[0].name_ascii
        # pin = data.get("pincode")
        phone = data.get("phone")
        sms_activation_code = generate_sms_activation_code()
        _data = {"password": password, "email": email,
            "first_name": first_name, 
            # "last_name": last_name,
            # "country": country, "address": address, "city": city,
            # "state": state, "pin": pin, "company": company, 
            # "country_code": country_code,
             "phone": phone, "sms_activation_code": sms_activation_code,
            "sms_activation_code_time": timeutils.strtime()}

        try:
            res = keystoneapi.create_user(_data)
        except Exception as ex:
            LOG.exception(ex)
            self.set_non_field_errors([self.get_default_error_message()])
            return None
        if not res.get("success"):
            self.set_non_field_errors([
                    res.get("error",
                            self.get_default_error_message()
                        )
                ])
            return None
        else:
            user = res["result"]
            user_id = user.get("id")
            try:
                send_registration_email(user, "signup/account_activation_email.html")
            except Exception as ex:
                LOG.exception(ex)
            try:
                generate_and_send_sms(phone, sms_activation_code)
            except Exception as ex:
                ##TODO(SM):Delete user from keystone ?
                LOG.exception(ex)
                self.set_non_field_errors([
                        self.get_default_error_message()
                    ])
                return None

            # return http.HttpResponseRedirect(
            #     reverse_lazy(
            #         'user_sms_activation',
            #         kwargs={"user_id": user_id}
            #     ))
            return render_to_response('signup/signup_success.html', 
                    {'email':settings.DEFAULT_FROM_EMAIL, 'user_id': user_id})