Ejemplo n.º 1
0
        public async Task <IHttpActionResult> ResetPassword(ForgotPasswordViewModel model)
        {
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                return(Ok <dynamic>(new { IsSuccess = 1, Status = 200, Message = "The User is not Registered!" }));
            }

            RepositoryBusinessProfiles repositoryBusiness = new RepositoryBusinessProfiles();
            var businessModel = repositoryBusiness.GetBusinessProfileById(user.BusinessId.Value);
            var code          = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

            var baseUrl = ConfigurationManager.AppSettings["PortalUrl"];

            //  if (!model.IsBusinessLogin)
            // {
            // var callbackUrl = Url.Route("ConfirmChangePassword", "Account", new { userId = user.Id, code = code, IsBusinessLogin = model.IsBusinessLogin }, protocol: "https");
            //var callbackUrl = Url.Route("ConfirmChangePassword", new { controller = "Account", userId = user.Id, code = code, IsBusinessLogin = model.IsBusinessLogin });
            var callbackUrl = string.Format("{0}/Account/ConfirmChangePassword?userId={1}&code={2}&IsBusinessLogin={3}", baseUrl, user.Id, code, model.IsBusinessLogin);

            callbackUrl = callbackUrl.Replace(":8080", "");
            var emailBody = TemplateManager.Forgotpassword(ConfigurationManager.AppSettings["PortalUri"], callbackUrl, user.BusinessId.Value, businessModel.Model.BusinessName.ToLower());
            await UserManager.SendEmailAsync(user.Id, "Change Password", emailBody);

            return(Ok <dynamic>(new { IsSuccess = 1, Status = 200, Message = "Success!" }));
            //ViewBag.Link = callbackUrl;
            //return View("UserVerification");
            //  }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> ChangePassword()
        {
            try
            {
                ForgotPasswordViewModel model = (ForgotPasswordViewModel)TempData["ForgotPasswordViewModel"];
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    if (model.IsBusinessLogin)
                    {
                        var returnurl = "/" + model.BusinessName.Replace(" ", "-") + "/BusinessUserVerification";
                        return(RedirectToLocal(returnurl));
                        //return RedirectToAction("BusinessUserVerification");
                    }
                    return(View("UserVerification"));
                }
                else
                {
                }
                Session.Clear();
                AuthenticationManager.SignOut();
                var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var rootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

                if (model.IsBusinessLogin)
                {
                    var route       = "/" + model.BusinessName.Replace(" ", "-") + "/BusinessUserConfirmation";
                    var callbackUrl = Url.RouteUrl("BusinessUserConfirmation", new { businessname = model.BusinessName.Replace(" ", "-"), userId = user.Id, code = code, IsBusinessLogin = model.IsBusinessLogin, bizid = model.bizId }, protocol: "https");
                    callbackUrl = callbackUrl.Replace(":8080", "");
                    var emailBody = TemplateManager.Forgotpassword(rootPath, callbackUrl, user.BusinessId.Value, model.BusinessName);
                    await UserManager.SendEmailAsync(user.Id, "Change Password", emailBody);

                    ViewBag.Link = callbackUrl;
                    var returnurl = "/" + model.BusinessName.Replace(" ", "-") + "/BusinessUserVerification";
                    return(RedirectToLocal(returnurl));
                }
                else
                {
                    RepositoryBusinessProfiles repositoryBusiness = new RepositoryBusinessProfiles();
                    var businessModel = repositoryBusiness.GetBusinessProfileById(user.BusinessId.Value);
                    var callbackUrl   = Url.Action("ConfirmChangePassword", "Account", new { userId = user.Id, code = code, IsBusinessLogin = model.IsBusinessLogin }, protocol: "https");
                    callbackUrl = callbackUrl.Replace(":8080", "");
                    var emailBody = TemplateManager.Forgotpassword(rootPath, callbackUrl, user.BusinessId.Value, businessModel.Model.BusinessName.ToLower());
                    await UserManager.SendEmailAsync(user.Id, "Change Password", emailBody);

                    ViewBag.Link = callbackUrl;
                    return(View("UserVerification"));
                }
                // If we got this far, something failed, redisplay form
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            return(View("Login"));
        }
        public IHttpActionResult GetByFilter()
        {
            FilterTask filter     = new FilterTask();
            var        repository = new RepositoryBusinessProfiles();
            var        response   = repository.GetAllList("ddd", filter);

            return(Ok <DataResponse <EntityList <EntityBusinessProfile> > >(response));
        }
Ejemplo n.º 4
0
        public IHttpActionResult InsertBusinessProfileData(BusinessProfileModel model)
        {
            var response = new DataResponse <EntityBusinessProfile>();
            EntityBusinessProfile entity = new EntityBusinessProfile();

            if (ModelState.IsValid)
            {
                entity.BusinessName = model.BusinessName;
                entity.Description  = model.Description;
                entity.Address      = model.Address;
                entity.About        = model.About;
                entity.DomainUrl    = model.DomainUrl;
                entity.City         = model.City;
                entity.State        = model.State;
                entity.Country      = model.Country;
                entity.IsActive     = model.IsActive;
                entity.OtherEmails  = model.OtherEmails;
                entity.DateRange    = model.DateRange;
                entity.SalesGroup   = model.SalesGroup;
                entity.CreatedBy    = CurrentUserId;
                entity.UpdatedBy    = CurrentUserId;
                entity.RelativeUrl  = model.RelativeUrl.Replace(" ", "-");
                entity.Id           = model.Id;
                entity.OtherEmails  = string.IsNullOrEmpty(model.OtherEmails) ? null : Regex.Replace(model.OtherEmails, @"[\[\]\""]+", "");
                if (!string.IsNullOrEmpty(model.DomainUrl))
                {
                    model.DomainUrl = model.DomainUrl.Replace(" ", "-");
                }
                if (model.Id > 0)
                {
                    response = new RepositoryBusinessProfiles().Update(entity);
                }
                return(Ok <DataResponse>(response));
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
        }