Exemple #1
0
        public async Task <Uri> ConfirmAuthenticationCode()
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:44327/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.PostAsJsonAsync(
                "api/SendPhoneNumber", "09333893318");

            var amSMSAuthentication = new AMSMSAuthentication
            {
                PhoneNumber        = "09333893318",
                AuthenticationCode = "code"
            };

            response = await client.PostAsJsonAsync("api/SendConfirmAuthenticationCode", amSMSAuthentication);

            var result = response.Content.ReadAsStringAsync().Result;

            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return(response.Headers.Location);
        }
Exemple #2
0
        public string SendConfirmAuthenticationCode(AMSMSAuthentication amSMSAuthentication)
        {
            string userId = string.Empty;

            try
            {
                var user = UserManager.Users.SingleOrDefault(u => u.PhoneNumber == amSMSAuthentication.PhoneNumber);

                if (user != null && user.AuthenticationCode == amSMSAuthentication.AuthenticationCode)
                {
                    user.PhoneNumberConfirmed = true;
                    userId = user.Id;

                    // UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>());

                    UserManager.RemovePassword(userId);

                    var password = BLHelper.GeneratePassword(6);

                    UserManager.AddPassword(userId, password);

                    var smsResult = BLHelper.SendSMS(
                        amSMSAuthentication.PhoneNumber,
                        "به WERC خوش آمدید" + "\n" +
                        " جهت ورود به حساب کاربریتان در سایت WERC.com و استفاده از سرویس های ارایه شده از اطلاعات زیر استفاده نمایید : " + "\n" +
                        "نام کاربری : " + amSMSAuthentication.PhoneNumber + "\n" +
                        "رمز عبور : " + password + "\n" + ""
                        );

                    if (smsResult == 10) //Delivered
                    {
                        //1   در صف ارسال قرار دارد.
                        //2   زمان بندی شده(ارسال در تاریخ معین).
                        //4   ارسال شده به مخابرات.
                        //5   ارسال شده به مخابرات(همانند وضعیت 4)
                        //6   خطا در ارسال پیام که توسط سر شماره پیش می آید و به معنی عدم رسیدن پیامک می باشد(Failed)
                        //10  رسیده به گیرنده(Delivered)
                        //11  نرسیده به گیرنده ،این وضعیت به دلایلی از جمله خاموش یا خارج از دسترس بودن گیرنده اتفاق می افتد(Undelivered)
                        //13  ارسال پیام از سمت کاربر لغو شده یا در ارسال آن مشکلی پیش آمده که هزینه آن به حساب برگشت داده میشود.
                        //14  بلاک شده است،عدم تمایل گیرنده به دریافت پیامک از خطوط تبلیغاتی که هزینه آن به حساب برگشت داده میشود
                        //100 شناسه پیامک نامعتبر است.(به این معنی که شناسه پیام در پایگاه داده کاوه نگار ثبت نشده است یا متعلق به شما نمی باشد)
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(userId);
        }