예제 #1
0
        public ActionResult DoLogin(LoginModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    string password = model.Password.ToEnctyptedPassword();
                    // check user credential
                    var user = UnitofWork.RepoUser.Where(x => x.Email.ToLower() == model.Email.ToLower() && x.Password == password && x.IsAdmin == true && x.IsActive == true).FirstOrDefault();
                    if (user != null)
                    {
                        SessionHelper.UserId   = user.UserID;
                        SessionHelper.UserName = user.Ownername ?? "";
                        SessionHelper.IsAdmin  = user.IsAdmin;

                        if (model.RememberMe)
                        {
                            SessionHelper.UserCookie = user.UserID.ToString().ToEnctypt();
                        }

                        #region Add to History
                        var browser = Request.Browser;

                        UnitofWork.RepoLoginHistory.Add(new LoginHistory()
                        {
                            Browser   = browser.Browser,
                            TimeStamp = utilityHelper.CurrentDateTime,
                            UserID    = user.UserID,
                            IPaddress = utilityHelper.IpAddress(),
                            Device    = browser.IsMobileDevice ? "Mobile" : "Web",
                        });
                        UnitofWork.Commit();
                        #endregion

                        TransMessage.Status  = MessageStatus.Success;
                        TransMessage.Message = string.IsNullOrEmpty(model.ReturnUrl) ? Url.Action("Index", "Dashboard") : model.ReturnUrl;
                    }
                    else
                    {
                        TransMessage.Message = utilityHelper.ReadGlobalMessage("Login", "ErrorMessage");
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("Login", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(TransMessage, JsonRequestBehavior.DenyGet));
        }
        public JsonResult ChangePassword(ChangePasswordModel model)
        {
            model.TransMessage        = new TransactionMessage();
            model.TransMessage.Status = MessageStatus.Error;

            try
            {
                if (ModelState.IsValid)
                {
                    if (model.NewPassword == model.ConfirmPassword)
                    {
                        var user = UnitofWork.RepoUser.Where(x => x.UserID == SessionHelper.UserId).FirstOrDefault();
                        if (user != null && user.Password == model.CurrentPassword.ToEnctyptedPassword())
                        {
                            string newPassword = model.NewPassword.ToEnctyptedPassword();
                            if (user.Password != newPassword)
                            {
                                // Update Password
                                user.Password = newPassword;
                                UnitofWork.Commit();

                                model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ChangePassword", "SuccessMessage");
                                model.TransMessage.Status  = MessageStatus.Success;
                            }
                            else
                            {
                                // old n new password are same
                                model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ChangePassword", "OldAndNewSame");
                            }
                        }
                        else
                        {
                            // wrong current password
                            model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ChangePassword", "WrongPassword");
                        }
                    }
                    else
                    {
                        // new n confirm not match
                        model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ChangePassword", "NotMatch");
                    }
                }
                else
                {
                    model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ChangePassword", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
예제 #3
0
        public JsonResult ResetPassword(ForgotPasswordModel model)
        {
            model.TransMessage        = new TransactionMessage();
            model.TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    // check user Email
                    var user = UnitofWork.RepoUser.Where(x => x.Email.ToLower() == model.Email.ToLower()).FirstOrDefault();
                    if (user != null)
                    {
                        Guid   gid      = Guid.NewGuid();
                        string password = gid.ToString().Substring(0, 8);
                        // Update Password
                        user.Password = password.ToEnctyptedPassword();
                        UnitofWork.Commit();

                        // Send Mail
                        string subject  = "Reset Password";
                        string template = utilityHelper.ReadFromFile("ForgotPassword.html");
                        template = template.Replace("[Name]", user.Ownername);
                        template = template.Replace("[Email]", user.Email);
                        template = template.Replace("[Password]", password);
                        template = template.Replace("[SiteUrl]", utilityHelper.SiteUrl());
                        Framework.utilityHelper.SendMail(user.Email, subject, template);

                        model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ForgotPassword", "SuccessMessage");
                        model.TransMessage.Status  = MessageStatus.Success;
                    }
                    else
                    {
                        model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ForgotPassword", "ErrorMessage");
                    }
                }
                else
                {
                    model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ForgotPassword", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
예제 #4
0
 /// <summary>
 /// Save all changes in database.
 /// </summary>
 public void CommitChanges()
 {
     _unitofWork.Commit();
 }
예제 #5
0
        public Task Execute(IJobExecutionContext context)
        {
            _logger.LogInformation("------------------------------------------------------");
            var schedule = context.Scheduler;

            //Default job runs
            using (var uow = new UnitofWork(_config))
            {
                var result = uow.CheckRegisterRepository.GetCheckUpdates().ToList();

                if (result.Any() && context.JobDetail.Key.Name != "MonitorMainJob")
                {
                    //match the curent job to be executed
                    var currentData = result.Where(x => x.Id == new Guid(context.JobDetail.Key.Name) &&
                                                   x.IsActive && x.IsScheduled).FirstOrDefault();
                    if (currentData != null)
                    {
                        _logger.LogInformation($"url execution Begin");
                        // check url
                        Task taskexecute = Task.Run(() => RunUrl(currentData)
                                                    .ContinueWith((data) =>
                        {
                            uow.CheckRunRepository.AddCheckRun(
                                new CheckRun
                            {
                                CheckId   = currentData.Id,
                                Status    = data.Result.Item1,
                                RunTime   = data.Result.Item2.ToString(),
                                LastRunOn = DateTime.UtcNow
                            });
                            return(data.Result.Item1);
                        }).ContinueWith((status) =>
                        {
                            if (status.Result != UrlStatus.UP.ToString())
                            {
                                SendEmail();
                            }
                        }));
                        taskexecute.Wait();
                        _logger.LogInformation($"----url execution End---");
                    }
                }

                if (result.Any() && context.JobDetail.Key.Name == "MonitorMainJob")
                {
                    //add new job or start existing
                    foreach (var item in result.Where(x => (x.IsActive && !x.IsScheduled) || (x.IsActive && x.IsScheduled && (!context.Scheduler.CheckExists(new JobKey($"{x.Id}")).Result))))
                    {
                        _logger.LogInformation($"{context.JobDetail.Key}--created---");
                        schedule.ScheduleJob(CreateJob(_jobSchedules, item), CreateTrigger(_jobSchedules, item));
                        uow.CheckRegisterRepository.UpdateCheckSchedule(item.Id, true);
                    }

                    //delete disable  job
                    foreach (var item in result.Where(x => !x.IsActive && !x.IsScheduled).ToList())
                    {
                        _logger.LogInformation($"{context.JobDetail.Key}--Deleted---");
                        schedule.DeleteJob(new JobKey($"{item.Id}"));
                    }
                }
                uow.Commit();
            }


            _logger.LogInformation($"Actual fire {context.FireTimeUtc} and next {context.NextFireTimeUtc}");
            _logger.LogInformation("---------------*********------------------------------");
            return(Task.CompletedTask);
        }