public IActionResult ConfirmRegister([FromServices] AreaDbContext DB)
        {
            List <Models.ErrorLog> error = new List <Models.ErrorLog>();

            if (String.IsNullOrEmpty(HttpContext.Session.GetString("tmpCode")))
            {
                ClientGmail client = new ClientGmail();
                Random      rnd    = new Random();
                string      code   = rnd.Next(1000, 9999).ToString();

                HttpContext.Session.SetString("tmpCode", code);
                client.SendMail(HttpContext.Session.GetString("tmpEmail"), code);
            }
            else
            {
                Models.ErrorLog elem = new Models.ErrorLog();
                elem.message = "Wrong code entered";

                elem.enabl = true;
                HttpContext.Session.SetString("tmpCode", "");
                error.Add(elem);
            }
            ViewData["ErrorConf"] = error;
            return(View());
        }
Exemple #2
0
 public void GenerateLog(string msg)
 {
     Models.ErrorLog Errthrow = new Models.ErrorLog();
     Errthrow.LogType            = "Debug";
     Errthrow.ErrorMessage       = msg;
     Errthrow.LogCreatedDateTime = DateTime.Now;
     Db.ErrorLogs.Add(Errthrow);
     Db.SaveChanges();
 }
Exemple #3
0
 public void LogTime(string place, long time)
 {
     Models.ErrorLog Errthrow = new Models.ErrorLog();
     Errthrow.LogType            = "Debug";
     Errthrow.ErrorMessage       = time.ToString();
     Errthrow.StackTrace         = place;
     Errthrow.LogCreatedDateTime = DateTime.Now;
     Db.ErrorLogs.Add(Errthrow);
     Db.SaveChanges();
 }
        public IActionResult Login([FromServices] AreaDbContext DB)
        {
            List <Models.ErrorLog> error = new List <Models.ErrorLog>();

            Models.ErrorLog elem = new Models.ErrorLog();
            elem.message = "Wrong User or Password";

            elem.enabl = !(String.IsNullOrEmpty(HttpContext.Session.GetString("username")) && String.IsNullOrEmpty(HttpContext.Session.GetString("password")));
            HttpContext.Session.SetString("username", "");
            HttpContext.Session.SetString("passwd", "");
            error.Add(elem);
            ViewData["ErrorLog"] = error;
            return(View());
        }
        public IActionResult Register([FromServices] AreaDbContext DB)
        {
            List <Models.ErrorLog> error = new List <Models.ErrorLog>();

            Models.ErrorLog elem = new Models.ErrorLog();
            elem.message = "Passwords don't match";

            elem.enabl = !(HttpContext.Session.GetString("tmpPass") == HttpContext.Session.GetString("tmpConfirm"));
            HttpContext.Session.SetString("tmpConfirm", "");
            HttpContext.Session.SetString("tmpPass", "");
            error.Add(elem);
            ViewData["ErrorReg"] = error;
            return(View());
        }
Exemple #6
0
 public static void LogError(PlaylistContext context, string source, string message, Visitor visitor)
 {
     try
     {
         Models.ErrorLog errorLog = new Models.ErrorLog();
         errorLog.IdVisitorNavigation = visitor;
         errorLog.Message             = message;
         errorLog.Source = source;
         context.ErrorLog.Add(errorLog);
         context.SaveChanges();
         Mail.SendMail("Error", "Source:<br>" + source + "<br>Message:<br>" + message);
     }
     catch (Exception e)
     {
         Models.ErrorLog errorLog = new Models.ErrorLog();
         errorLog.IdVisitorNavigation = visitor;
         errorLog.Message             = e.ToString();
         errorLog.Source = "ErrorLogger";
         context.ErrorLog.Add(errorLog);
         context.SaveChanges();
         Mail.SendMail("Critical Error", e.ToString());
     }
 }
Exemple #7
0
        /// <summary>
        /// Exception handling & Create the Error Logs to the Errorlog Table
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <param name="UserId">UserId</param>
        /// using the multiple catch and show the custom Message related to the Exception
        /// <returns></returns>
        public ExceptionProcessing ErrorLog(Exception ex, string UserId)
        {
            ExceptionProcessing exceptionp = new ExceptionProcessing();

            Models.ErrorLog Errthrow = new Models.ErrorLog();
            if (ex is MissingMemberException || ex is NotSupportedException)
            {
                Errthrow.LogPriority = "Heigh";
                exceptionp.Code      = HttpStatusCode.InternalServerError;
                exceptionp.Message   = "{\"Error_Code\": 101,\"Message\": \" System Not Respond.\"}";
            }
            else if (ex is FormatException || ex is OverflowException || ex is ArgumentNullException)
            {
                Errthrow.LogPriority = "Medium";
                exceptionp.Code      = HttpStatusCode.BadRequest;
                exceptionp.Message   = "{\"Error_Code\": 102,\"Message\": \" Invalid Input/output Format.\"}";
            }
            else if (ex is BadImageFormatException || ex is XmlException || ex is JsonException || ex is InvalidCastException)
            {
                Errthrow.LogPriority = "Medium";
                exceptionp.Code      = HttpStatusCode.NotAcceptable;
                exceptionp.Message   = "{\"Error_Code\": 103,\"Message\": \" Unable to Parse. \"}";
            }
            else if (ex is IOException)
            {
                Errthrow.LogPriority = "Heigh";
                exceptionp.Code      = HttpStatusCode.Forbidden;
                exceptionp.Message   = "{\"Error_Code\": 104,\"Message\": \" Unable to Perform IO Operation.\"}";
            }
            else if (ex is SqlException)
            {
                Errthrow.LogPriority = "Heigh";
                exceptionp.Code      = HttpStatusCode.InternalServerError;
                exceptionp.Message   = "{\"Error_Code\": 105,\"Message\": \"Unable to Perform DatatBase Operation.\"}";
            }
            else if (ex is NullReferenceException)
            {
                Errthrow.LogPriority = "Heigh";
                exceptionp.Code      = HttpStatusCode.InternalServerError;
                exceptionp.Message   = "{\"Error_Code\": 107,\"Message\": \"Nullable Value Exception.\"}";
            }
            else if (ex is UnauthorizedAccessException)
            {
                Errthrow.LogPriority = "Heigh";
                exceptionp.Code      = HttpStatusCode.Forbidden;
                exceptionp.Message   = "The User is unauthorized.";
            }
            else
            {
                Errthrow.LogPriority = "Medium";
                exceptionp.Code      = HttpStatusCode.InternalServerError;
                exceptionp.Message   = "{\"Error_Code\": 108,\"Message\": \"Unhandled Exception.\"}";
            }
            Errthrow.ErrorCode          = ((int)exceptionp.Code).ToString();
            Errthrow.LogUserId          = UserId;
            Errthrow.LogType            = "Error";
            Errthrow.StackTrace         = ex.StackTrace;
            Errthrow.InnerMessage       = exceptionp.Message;
            Errthrow.ErrorMessage       = ex.Message;
            Errthrow.ErrorSource        = ex.Source;
            Errthrow.LogCreatedDateTime = DateTime.Now;
            Db.ErrorLogs.Add(Errthrow);
            Db.SaveChanges();
            return(exceptionp);
        }
        public IActionResult RequestForm(string songRequest, string email, string bandName, string bandLocation, bool GDPRConsent)
        {
            Visitor visitor = null;

            try
            {
                //validify all input
                if (HttpContext.Session.GetString("captcha") != "verified" || String.IsNullOrEmpty(HttpContext.Session.GetString("captcha")))
                {
                    return(BadRequest("Please verify that you are human"));
                }
                if (!Functions.Validify.IsValidEmail(email))
                {
                    return(BadRequest("Invalid email"));
                }
                if (String.IsNullOrEmpty(songRequest) || String.IsNullOrEmpty(bandName) || String.IsNullOrEmpty(bandLocation))
                {
                    return(BadRequest("Please fill up all form fields"));
                }
                if (!GDPRConsent)
                {
                    return(BadRequest("You have to agree with our Privacy Policy"));
                }

                songRequest = HttpUtility.HtmlEncode(songRequest);
                bandName    = HttpUtility.HtmlEncode(bandName);
                _context.Database.EnsureCreated();

                visitor = EntityFW.InitializeVisitor(_context, _accessor);
                //Log
                Functions.Log.LogActivity(_context, "Index", "Sending form", visitor);

                //Check if band exists if not, create one
                Band band = _context.Band.Where(v => v.BandName == bandName).FirstOrDefault() ?? new Band
                {
                    BandName     = bandName,
                    BandLocation = bandLocation
                };
                User user = _context.User.Where(v => v.Email == email).FirstOrDefault() ?? new User {
                    Email       = email,
                    ConsentGdpr = GDPRConsent
                };

                UserHasVisitor UHV = _context.UserHasVisitor.Where(v => v.UserIdUserNavigation == user && v.VisitorIdVisitorNavigation == visitor).FirstOrDefault();
                if (UHV == null)
                {
                    UHV = new UserHasVisitor {
                        UserIdUserNavigation       = user,
                        VisitorIdVisitorNavigation = visitor
                    };
                    _context.UserHasVisitor.Add(UHV);
                }
                BandHasUser BHU = _context.BandHasUser.Where(v => v.UserIdUserNavigation == user && v.BandIdBandNavigation == band).FirstOrDefault();
                if (BHU == null)
                {
                    BHU = new BandHasUser {
                        UserIdUserNavigation = user,
                        BandIdBandNavigation = band
                    };
                    _context.BandHasUser.Add(BHU);
                }
                //Create new song request
                SongRequest newSongRequest = new SongRequest
                {
                    SongRequest1     = songRequest,
                    IdUserNavigation = user
                };
                _context.SongRequest.Add(newSongRequest);
                string[] songs = EntityFW.GetSongs(songRequest);
                foreach (string song in songs)
                {
                    if (song.Contains("open.spotify.com") || song.Contains("youtube.com"))
                    {
                        _context.Song.Add(new Song {
                            SongUrl = song,
                            IdSongRequestNavigation = newSongRequest,
                            IdBandNavigation        = band
                        });
                    }
                    else
                    {
                        Functions.Log.LogError(_context, "Index-Send - Form - Invalid song url", song, visitor);
                    }
                }

                try
                {
                    Functions.Mail.SendMail("New song request", stringBuilder.Append("Band: ").Append(bandName).Append(" - From: ").Append(bandLocation).Append(" - Email: ").Append(email).Append("<br>Message:<br>").Append(songRequest).ToString());
                }
                catch (Exception e)
                {
                    Models.ErrorLog errorLog = new Models.ErrorLog();
                    errorLog.IdVisitorNavigation = visitor;
                    errorLog.Message             = e.Message;
                    errorLog.Source = "Index-Send Form Email - " + e.Source;
                    _context.ErrorLog.Add(errorLog);
                }
                _context.SaveChanges();
                return(Ok("Thank you!"));
            }
            catch (Exception e)
            {
                Functions.Log.LogError(_context, "Index-Send Form", e.ToString(), visitor ?? EntityFW.InitializeVisitor(_context, _accessor));
                return(BadRequest());
            }
        }
        public override void OnException(ExceptionContext filterContext)
        {
            Exception ex = filterContext.Exception;

            Exception innerEx = ex.InnerException == null ? ex : ex.InnerException;

            while (innerEx.InnerException != null)
            {
                innerEx = innerEx.InnerException;
            }

            var  sessionModel = filterContext.HttpContext.Session[Keys.SessionKey] as MemberSessionVM;
            Guid logMemberId  = default(Guid);
            var  account      = string.Empty;

            if (sessionModel != null)
            {
                logMemberId = sessionModel.MemberID;
                account     = sessionModel.Account;
            }

            var logger = new Models.ErrorLog
            {
                LogID       = Guid.NewGuid(),
                LogMemberID = logMemberId,
                LogTime     = DateTime.Now,
                Message     = ex.Message,
                StackTrace  = ex.StackTrace,
                Source      = ex.Source,
                TargetSite  = ex.TargetSite.ToString(),
                HelpLink    = ex.HelpLink,
                HResult     = ex.HResult.ToString(),
                Account     = account,
                ErrorUrl    = filterContext.HttpContext.Request.Url.AbsoluteUri,
                View        = false
            };

            BackgroundJob.Enqueue(() => StartLog(logger));

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new JsonResult()
                {
                    Data = new JsonData <object>()
                    {
                        info   = "应用程序异常,请联系管理员",
                        status = "n",
                        others = new
                        {
                            logger.Message,
                            logger.Source
                        }
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
            else
            {
                filterContext.Result = new ContentResult()
                {
                    Content = "应用程序异常,请联系管理员,异常简要信息:" + logger.Message
                };
            }

            filterContext.ExceptionHandled = true;
            base.OnException(filterContext);
        }