public ActionResult SendSMS(Message message)
        {
            var          from = _userService.GetUserByIdentity(User.Identity.Name);
            SendEmailSMS send = new SendEmailSMS();

            message.FromUser   = from.UserId;
            message.SenderName = from.Name;
            message.Type       = "SMS";
            message.ISRead     = true;
            if (Request.Form["SendToAll"] != null)
            {
                message.Email  = "";
                message.Mobile = "رسال به همه";
                IList <string> mobileList = new List <string>();

                foreach (var item in _userService.GetAllUsers())
                {
                    mobileList.Add(item.moblie);
                }
                send.SendSMS(mobileList, message.ContentMessage);
            }
            else
            {
                try
                {
                    send.SendSMS(new[] { message.Mobile }, message.ContentMessage);
                }
                catch
                {
                }
            }
            _messageService.Add(message);
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Login(LoginViewModel login, string returnUrl, string captcha)
        {
            string result = googlecaptcha(null);

            //// validate the response from Google reCaptcha
            var captChaesponse = JsonConvert.DeserializeObject <reCaptchaResponse>(result);

            if (!captChaesponse.Success)
            {
                ViewBag.Message = "لطفا ابتدا کادر تایید هویتی را علامت بزنید!";
                return(View());
            }

            // go ahead and write code to validate mobile password against database
            var Qlogin = _userService.LogIn(login.UserName, login.password);

            if (Qlogin != null)
            {
                if (Qlogin.ISActive == true)
                {
                    FormsAuthentication.SetAuthCookie(login.UserName, login.Remember);
                    if (returnUrl != null)
                    {
                        return(Redirect(returnUrl));
                    }
                    return(Redirect("/"));
                }
                else
                {
                    long activecode = LongRandom(min: 123456, max: 654321, rand: new Random());
                    Qlogin.ActiveCode     = activecode.ToString();
                    Qlogin.activecodeDate = DateTime.Now;
                    _userService.Edit(Qlogin);
                    ///send SMS to number
                    SendEmailSMS send = new SendEmailSMS();
                    try
                    {
                        string bodySms = "کد تایید شما : " + activecode.ToString();
                        send.SendSMS(new[] { Qlogin.moblie }, bodySms);
                    }
                    catch { }
                    try
                    {
                        string bodyemail = PartialToStringClass.RenderPartialView("Email", "ActiveUser", Qlogin);
                        send.SendEmail(new[] { Qlogin.Email }, "کد تاییدیه حساب", bodyemail);
                    }
                    catch { }
                    RegisterViewModel register = new RegisterViewModel();
                    register.UserName = Qlogin.UserName;
                    ViewBag.status    = "حساب شما غیر فعال است";
                    return(View("RegisteredActivate", register));
                }
            }
            else
            {
                ModelState.AddModelError("UserName", "نام کاربری  یا رمز عبور اشتباه میباشد!");
            }
            return(View());
        }
Beispiel #3
0
        public ActionResult SendForgotPass(string userName)
        {
            var          user = _userService.GetByUserName(userName);
            SendEmailSMS send = new SendEmailSMS();

            if (user != null)
            {
                DateTime till = DateTime.Now.AddMinutes(-2);
                if (user.activecodeDate > till)
                {
                    return(Json("Time", JsonRequestBehavior.AllowGet));
                }
                string[] linkgenerate = Guid.NewGuid().ToString().Split('-');
                user.ActiveCode     = linkgenerate[0];
                user.activecodeDate = DateTime.Now;
                _userService.Edit(user);
                // // send SMS to number
                try
                {
                    string bodySms = Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/changePass/" + user.ActiveCode;
                    send.SendSMS(new[] { user.moblie }, bodySms);
                }
                catch { }
                try
                {
                    string bodyemail = PartialToStringClass.RenderPartialView("Email", "ForgotPass", user);
                    send.SendEmail(new[] { user.Email }, "بازیابی رمز عبور", bodyemail);
                }
                catch { }

                return(Json("<div class=\"alert alert-success rtl\" role=\"alert\">لینک تغییر رمز عبور به موبایل و ایمیل شما ارسال شد</div>", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("<div class=\"alert alert-danger rtl\" role=\"alert\"> <strong>خطا </strong> کاربری یافت نشد</div>", JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #4
0
        public JsonResult SendAgain(string userName)
        {
            DateTime     till = DateTime.Now.AddMinutes(-2);
            var          user = _userService.GetByUserName(userName);
            SendEmailSMS send = new SendEmailSMS();

            if (user != null)
            {
                if (user.activecodeDate > till)
                {
                    return(Json("Time", JsonRequestBehavior.AllowGet));
                }
                long activecode = LongRandom(min: 123456, max: 654321, rand: new Random());
                user.ActiveCode     = activecode.ToString();
                user.activecodeDate = DateTime.Now;
                _userService.Edit(user);
                ///send SMS to number
                try
                {
                    string bodySms = "کد تایید شما : " + activecode.ToString();
                    send.SendSMS(new[] { user.moblie }, bodySms);
                }
                catch { }
                try
                {
                    string bodyemail = PartialToStringClass.RenderPartialView("Email", "ActiveUser", user);
                    send.SendEmail(new[] { user.Email }, "کد تاییدیه حساب", bodyemail);
                }
                catch { }
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #5
0
        public ActionResult Register(RegisterViewModel register)
        {
            if (register.Moblie == null || register.Email == null)
            {
                ModelState.AddModelError("", "لطفا ایمیل و شماره تلفن را برای فعالسازی حسابتان وارد کنید!");
            }

            string       result = googlecaptcha(null);
            SendEmailSMS send   = new SendEmailSMS();

            //// validate the response from Google reCaptcha
            var captChaesponse = JsonConvert.DeserializeObject <reCaptchaResponse>(result);

            if (!captChaesponse.Success)
            {
                ViewBag.Message = "لطفا ابتدا کادر تایید هویتی را علامت بزنید!";
                return(View());
            }


            long activeCode = LongRandom(min: 123456, max: 654321, rand: new Random());


            if (ModelState.IsValid)
            {
                User user = new User()
                {
                    UserName       = register.UserName.Trim(),
                    Name           = register.FirstName + " " + register.LastName,
                    Password       = register.Pass.Trim(),
                    moblie         = register.Moblie.Trim(),
                    Email          = register.Email.Trim(),
                    AddedDate      = DateTime.Now,
                    Profile        = "no-photo.jpg",
                    RoleId         = 2,
                    IP             = ServiceLayer.AddressIpClass.GetPublicIPAddress(),
                    ActiveCode     = activeCode.ToString(),
                    activecodeDate = DateTime.Now,
                    ISActive       = false
                };

                try
                {
                    string bodySms = "کد تایید شما : " + activeCode.ToString();
                    send.SendSMS(new[] { register.Moblie }, bodySms);
                }
                catch { }
                try
                {
                    string bodyemail = PartialToStringClass.RenderPartialView("Email", "ActiveUser", register);
                    send.SendEmail(new[] { register.Email }, "کد تاییدیه حساب", bodyemail);
                }
                catch { }

                _userService.Add(user);
                ViewBag.status = "برای فعال کردن حسابتان کد تائیدیه را وارد کنید!";
                return(View("RegisteredActivate", register));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "خطایی وجود دارد");
            }
            return(View());
        }