Ejemplo n.º 1
0
        public ActionResult RequestPassword([FromBody] int id)
        {
            try
            {
                User user = null;

                using (var userDAO = new UserDAO())
                    user = userDAO.Get(id);

                Token token     = new Token(user);
                var   emurbMail = new SystemMail(_smtp, _port, _login, _password);

                if (user != null && emurbMail.SendNewPasswordMail(Request, token))
                {
                    using (var tokenDAO = new TokenDAO())
                        tokenDAO.Add(token);

                    return(StatusCode(200, new { Message = "Enviado" }));
                }

                return(StatusCode(424, new { Message = "Erro ao gerar Token" }));
            }

            catch (Exception ex)
            {
                return(StatusCode(500, new { Message = "Houve um erro ao enviar o token para o email deste usuário" }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SystemMail = await _context.system_mail.FirstOrDefaultAsync(m => m.system_mail_no == id);

            if (SystemMail == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 3
0
        public void Config(SystemMail which, string pwd)
        {
            switch (which)
            {
            case SystemMail.Gmail:
                this.Config("smtp.gmail.com", 587, true, "*****@*****.**", pwd);
                this.SetFrom("*****@*****.**", "System");
                break;

            case SystemMail.Yahoo:
                this.Config("smtp.mail.yahoo.com", 25, false, "wxm395115323", pwd);
                this.SetFrom("*****@*****.**", "System");
                break;
            }
        }
Ejemplo n.º 4
0
        public static string SendTasks(DataTable dataTable)
        {
            DateTime dateNow     = DateTime.Now;
            string   recipient   = "*****@*****.**";
            int      tasksSended = 0;

            foreach (DataRow dataRow in dataTable.Rows)
            {
                try {
                    string date = dataRow[0].ToString();
                    if (!DateTime.TryParse(date, out DateTime dateTime))
                    {
                        continue;
                    }

                    if (!dateTime.Date.Equals(dateNow.Date))
                    {
                        continue;
                    }

                    string task        = dataRow[1].ToString();
                    string responsible = dataRow[2].ToString();
                    string initiator   = dataRow[3].ToString();

                    if (string.IsNullOrEmpty(task) ||
                        string.IsNullOrEmpty(responsible) ||
                        string.IsNullOrEmpty(initiator))
                    {
                        Logging.ToLog("Строка содержит пустые ячейки: задача - " + task +
                                      ", ответственный - " + responsible + ", инициатор - " + initiator);
                        Logging.ToLog("Пропуск");
                        continue;
                    }

                    string body = "Назначить на: " + responsible + Environment.NewLine +
                                  "Задача: " + task + Environment.NewLine +
                                  "Инициатор: " + initiator;

                    SystemMail.SendMail("Заявка", body, recipient, addSignature: false);
                    tasksSended++;
                } catch (Exception e) {
                    Logging.ToLog(e.Message + Environment.NewLine + e.StackTrace);
                }
            }

            return("Задач отправлено: " + tasksSended);
        }
Ejemplo n.º 5
0
        public ActionResult Add([FromBody] User user)
        {
            try
            {
                User existingUser = null;

                using (var userDAO = new UserDAO())
                {
                    existingUser = userDAO.GetByEmail(user.Email);

                    if (existingUser != null)
                    {
                        user.Id = existingUser.Id;
                    }

                    else
                    {
                        user.Id = userDAO.Add(user);
                    }
                }

                if (user.Id != 0)
                {
                    Token token     = new Token(user);
                    var   emurbMail = new SystemMail(_smtp, _port, _login, _password);

                    if (emurbMail.SendNewPasswordMail(Request, token))
                    {
                        using (var tokenDAO = new TokenDAO())
                            tokenDAO.Add(token);

                        return(StatusCode(201, new {
                            Message = (existingUser != null) ? "Usuário já cadastrado, email reenviado com sucesso" : "Adicionado com sucesso"
                        }));
                    }

                    return(StatusCode(424, new { Message = "Falha ao enviar email" }));
                }

                return(StatusCode(304, new { Message = "Não adicionado" }));
            }

            catch (Exception ex)
            {
                return(StatusCode(500, new { Message = "Falha" }));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SystemMail = await _context.system_mail.FindAsync(id);

            if (SystemMail != null)
            {
                _context.system_mail.Remove(SystemMail);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 7
0
        private void ReadUserCertificate(string userName)
        {
            string userCertificate = string.Empty;

            if (IsSettingsFileExist(fileUserCertificatesINI))
            {
                userCertificate = IniFile.ReadValue("Main", Environment.UserName, fileUserCertificatesINI);
            }

            if (string.IsNullOrEmpty(userCertificate) &&
                IsSettingsFileExist(fileUserCertificatesKontur))
            {
                try {
                    using (TextFieldParser csvParser = new TextFieldParser(fileUserCertificatesKontur, Encoding.GetEncoding("windows-1251"))) {
                        csvParser.CommentTokens = new string[] { "#" };
                        csvParser.SetDelimiters(new string[] { ";" });
                        csvParser.HasFieldsEnclosedInQuotes = true;
                        csvParser.ReadLine();

                        DateTime validTo = new DateTime();

                        while (!csvParser.EndOfData)
                        {
                            string[] fields = csvParser.ReadFields();
                            if (fields.Length < 14)
                            {
                                continue;
                            }

                            string lineUserName = fields[3];
                            if (!ClearString(lineUserName).Equals(ClearString(userName)))
                            {
                                continue;
                            }

                            string isRevoked = fields[10];
                            if (isRevoked.Equals("1"))
                            {
                                continue;
                            }

                            string   lineCertificateSN = fields[6];
                            DateTime lineValidTo       = DateTime.Parse(fields[9]);
                            if (string.IsNullOrEmpty(userCertificate))
                            {
                                userCertificate = lineCertificateSN;
                                validTo         = lineValidTo;
                                continue;
                            }

                            if (lineValidTo <= validTo)
                            {
                                continue;
                            }

                            userCertificate = lineCertificateSN;
                            validTo         = lineValidTo;
                        }
                    }
                } catch (Exception e) {
                    LoggingService.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
                }
            }

            if (string.IsNullOrEmpty(userCertificate))
            {
                string message = "Не удалось найти сертификат для пользователя '" +
                                 Environment.UserName + "@" + Environment.MachineName +
                                 "' в файлах: " + fileUserCertificatesINI +
                                 ", " + fileUserCertificatesKontur;
                LoggingService.LogMessageToFile(message);
                SystemMail.SendMail("FssAutoConfig", message);
                return;
            }

            Settings["certwsname"] = userCertificate;
        }