Пример #1
0
def resendEmail(request, user_id):
    try:
        res = keystoneapi.get_user(user_id)
        if not (res.get("success") or res.get("result")):
            raise Exception('Unable to get user details')
        user = res.get("result")
        send_registration_email(user, "signup/account_activation_email.html")
    except Exception as e:
        LOG.exception(e)
        return shortcuts.render_to_response('signup/signup_success.html', 
                {'email':settings.DEFAULT_FROM_EMAIL, 'user_id':user.get("id"),
                 'resentEmail':True, 'resentSuccess':False})
    return shortcuts.render_to_response('signup/signup_success.html', 
           {'email':settings.DEFAULT_FROM_EMAIL, 'user_id':user.get("id"),
            'resentEmail':True, 'resentSuccess':True})
Пример #2
0
    def handle(self, request, data):
        res = {}
        user = None
        try:
            code = data.get("code")
            user_id = data.get("user_id")
            try:
                res = keystoneapi.get_user(user_id)
            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(["Invalid Account"])
                return None                
            user = res.get("result")
            if not user:
                self.set_non_field_errors(["Invalid Account"])
                return None
            else:
                if user.get("enabled"):
                    self.set_non_field_errors(["Account already activated"])
                    return None
                else:
                    sms_activation_code = user.get("sms_activation_code")
                    sms_activation_code_time = \
                            user.get("sms_activation_code_time")
                    if not (sms_activation_code and sms_activation_code_time):
                        self.set_non_field_errors(["Invalid Activation Code"])
                        return None
                    if sms_activation_code not in [code]:
                        self.set_non_field_errors(["Invalid Activation Code"])
                        return None
                    if is_sms_expired(sms_activation_code_time):
                        self.set_non_field_errors(["Activation Code Expired. Click 'Resend OTP'"])
                        return None
                    user_id = user.get("id")
                    if not user_id:
                        self.set_non_field_errors(["Invalid Account"])
                        return None
                    _data = {"user_id": user_id}
                    try:
                        res = keystoneapi.activate_user(_data)
                        keystoneapi.update_user(user_id, {"sms_activation_code" : ""})
                    except Exception as ex:
                        LOG.exception(ex)
                        self.set_non_field_errors([self.get_default_error_message()])
                        return None
                    try:
                        send_registration_email(user, "signup/registration_success_email.html")
                    except Exception as ex:
                        LOG.exception(ex)
        except Exception as ex:
            import traceback
            traceback.print_exc()
            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
        return res
Пример #3
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})