示例#1
0
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        if (phonenumber.Text.Trim() != "")
        {
            int smsCode = 0;
            CheckNumberResult res = CheckNumber(out smsCode);

            if (res == CheckNumberResult.Known)
            {
                if (smsCode.ToString() == password.Text.Trim())
                {
                    int passcode = new Random().Next(100000, 999999);
                    try
                    {
                        //необходимо создать пользователя и авторизовать его
                        BXUser user = new BXUser(); //BXUserManager.Create(phonenumber.Text.Trim(), "BXSqlMembershipProvider", out status);
                        user.IsApproved = true;
                        user.UserName = phonenumber.Text.Trim();
                        user.PasswordAnswer = "volotour";
                        user.Password = passcode.ToString();
                        user.ProviderName = "BXSqlMembershipProvider";
                        user.Email = phonenumber.Text.Trim() + "@volotour.ru";
                        user.Save();

                        Volotour.PersonalOffice.PersonalOfficeModule.sendsms("c79166104232", "ltkmaby123", phonenumber.Text, "Ваш пароль для volotour.ru " + passcode.ToString() + "\r\nРекомендуется сменить пароль!", true);

                        //Активируем профиль
                        CustomerProfilesCollection list = BXEntity<CustomerProfiles, CustomerProfilesCollection, CustomerProfiles.Scheme>.GetList(
                        new BXFilter(new IBXFilterItem[1]
                                    {
                                        (IBXFilterItem) new BXFilterItem(BXEntity<CustomerProfiles, CustomerProfilesCollection, CustomerProfiles.Scheme>.Fields.login, BXSqlFilterOperators.Equal, (object) phonenumber.Text.Trim())
                                    }),
                        new BXOrderBy(new BXOrderByPair[1]
                                    {
                                        new BXOrderByPair(BXEntity<CustomerProfiles, CustomerProfilesCollection, CustomerProfiles.Scheme>.Fields.registration_date, BXOrderByDirection.Asc)
                                    }));

                        if (list.Count() > 0)
                        {
                            CustomerProfiles cp = list[0];
                            cp.active = true;
                            cp.Save();

                        }


                        AuthUser(phonenumber.Text.Trim(), passcode.ToString());
                    }
                    catch (Exception ex)
                    {
                        hasErrors = true;
                        LastError = "У нас что то сломалось. Уже чиним. (" + ex.Message + ")";
                    }

                }
                else
                {
                    WrongSmsCode = true;
                    hasErrors = true;
                    LastError = "Неверный код подтверждения!";
                }
            }
            else
            {
                // Авторизовываем пользователя по логину - телефону
                AuthUser(phonenumber.Text.Trim(), password.Text);
            }
        }
        else
        {
            hasErrors = true;
            LastError = "Не введен номер!";
        }
        ErrorForm.Visible = hasErrors;
        ErrorMessage.Text = LastError;

        //changeform(res);
    }
    protected void SendSMSButton_Click(object sender, EventArgs e)
    {
        if (CheckNumber() == CheckNumberResult.Registered)
        {
            BXUserCollection list = BXEntity<BXUser, BXUserCollection, BXUser.Scheme>.GetList(
                        new BXFilter(new IBXFilterItem[1]
                                    {
                                        (IBXFilterItem) new BXFilterItem(BXEntity<BXUser, BXUserCollection, BXUser.Scheme>.Fields.UserName, BXSqlFilterOperators.Equal, (object) phonenumber.Text.Trim())
                                    }),
                        new BXOrderBy(new BXOrderByPair[1]
                                    {
                                        new BXOrderByPair(BXEntity<BXUser, BXUserCollection, BXUser.Scheme>.Fields.UserName, BXOrderByDirection.Asc)
                                    }));
            if (list.Count() > 0)
            {
                try
                {
                    int passcode = new Random().Next(100000, 999999);

                    BXUser duser = list[0];
                    //duser.ResetPassword(null, "volotour", passcode.ToString());
                    //duser.Save();
                    duser.Delete();

                    BXUser user = new BXUser();
                    user.IsApproved = true;
                    user.UserName = phonenumber.Text.Trim();
                    user.Password = passcode.ToString();
                    user.ProviderName = "BXSqlMembershipProvider";
                    user.Email = phonenumber.Text.Trim() + "@volotour.ru";
                    user.Save();

                    Volotour.PersonalOffice.PersonalOfficeModule.sendsms("c79166104232", "ltkmaby123", phonenumber.Text, "Ваш новый пароль для volotour.ru " + passcode.ToString() + "\r\nРекомендуется сменить пароль!", true);
                    SmsMessagePanel.Visible = true;
                    SendSMSButtonPanel.Visible = false;
                }
                catch (Exception ex)
                {
                    hasErrors = true;
                    LastError = ex.Message;
                }
            }
        }
        else
        {
            hasErrors = true;
            LastError = "Номер не зарегистрирован";
        }

        ErrorForm.Visible = hasErrors;
        ErrorMessage.Text = LastError;
    }