コード例 #1
0
        public ActionResult Password(string key)
        {
            using (var dataContext = new InnostarModelsContext())
            {
                var recoverRepository = new RecoverPasswordRequestRepository(dataContext);

                var requests = recoverRepository._Get(u => u.RequestKey.Equals(key) && u.IsActive).ToList();

                if (requests.Any())
                {
                    var request = requests.FirstOrDefault();

                    if (request == null)
                    {
                        throw new Exception("Данного запроса не существует");
                    }

                    var userRepository = new ChatUserRepository(dataContext);
                    var user           = userRepository._Get(e => e.Id == request.UserId).FirstOrDefault();

                    if (user == null)
                    {
                        throw new Exception("Произошла ошибка в обработке запроса. Обратитесь в службу поддержки");
                    }

                    return(View(new RecoverPasswordModel {
                        RequestId = request.Id, RequestKey = key, UserLogin = user.Login
                    }));
                }
                else
                {
                    return(RedirectToAction("NotFound", "Error"));
                }
            }
        }
コード例 #2
0
        public SimpleMembershipInitializer()
        {
            Database.SetInitializer <InnostarModelsContext>(null);

            try
            {
                bool firstLoad;

                using (var context = new InnostarModelsContext())
                {
                    firstLoad = DatabaseInitializer.InitializeDatabase(context);
                }

                WebSecurity.InitializeDatabaseConnection("DefaultConnection", "inf_Users", "UserId", "UserName", true);

                if (firstLoad)
                {
                    WebSecurity.CreateUserAndAccount("admin", "123456");
                    Roles.AddUserToRole("admin", "admin");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Ошибка", ex);
            }
        }
コード例 #3
0
        public void UploadPiece(string key, int order, Stream stream)
        {
            var    name     = Guid.NewGuid() + ".m4a";
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["PiecesPath"], name);

            if (!Directory.Exists(Directory.GetParent(filePath).FullName))
            {
                Directory.GetParent(filePath).Create();
            }

            using (var fileStream = File.Create(filePath))
            {
                stream.CopyTo(fileStream);
            }


            var time = DateTime.Now;

            var piece = new AudioPiece();

            piece.ExpirationTime   = time.AddDays(3);
            piece.Key              = key;
            piece.Order            = order;
            piece.PhysicalFileName = filePath;
            piece.UploadTime       = time;

            using (var context = new InnostarModelsContext())
            {
                var repository = new AudioPieceRepository(context);
                repository._Insert(piece);
                repository._Save();
            }
        }
コード例 #4
0
        public UploadData UploadFile(string fileName, int fileType, Stream stream)
        {
            using (var context = new InnostarModelsContext())
            {
                UploadData result = new UploadData();
                if (!Service.IsAuthorized(result))
                {
                    return(result);
                }
                DataFileRepository dataFileRepository = new DataFileRepository(context);
                DataFile           dataFile           = new DataFile();
                dataFile.OriginalFileName = fileName;
                dataFile.FileType         = fileType;
                dataFile.LocalFileName    = Guid.NewGuid().ToString() + Path.GetExtension(fileName);
                string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["FilesPath"], dataFile.LocalFileName);
                using (var fileStream = File.Create(filePath))
                {
                    stream.CopyTo(fileStream);
                }

                dataFileRepository._Insert(dataFile);
                dataFileRepository._Save();

                result.id      = dataFile.Id;
                result.code    = "200";
                result.message = "OK";
                return(result);
            }
        }
コード例 #5
0
        public void ConcatenatePieces(string key, int piecesCount)
        {
            using (var context = new InnostarModelsContext())
            {
                string filePath = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    ConfigurationManager.AppSettings["AudioFilesPath"],
                    string.Format("{0}.m4a", key));

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                var repository = new AudioPieceRepository(context);
                var paths      = repository.GetPiecePaths(key);

                var sourceFiles = paths as IList <string> ?? paths.ToList();

                if (!sourceFiles.Any() || (piecesCount > 0 && sourceFiles.Count() != piecesCount))
                {
                    throw new ArgumentException("some pieces are lost");
                }

                if (!Directory.Exists(Directory.GetParent(filePath).FullName))
                {
                    Directory.GetParent(filePath).Create();
                }

                string fileListPath = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    ConfigurationManager.AppSettings["PiecesPath"],
                    string.Format("{0}.txt", key));

                if (File.Exists(fileListPath))
                {
                    File.Delete(fileListPath);
                }

                using (var writer = File.AppendText(fileListPath))
                {
                    sourceFiles.ForEach(e => writer.WriteLine(@"file '{0}'", e));
                }

                FfmpegConcatenator.Concatenate(ConfigurationManager.AppSettings["FfmpegUtilityPath"], fileListPath, filePath);

                File.Delete(fileListPath);

                if (!File.Exists(filePath))
                {
                    throw new ArgumentException("file isn't concatenated");
                }
            }
        }
コード例 #6
0
        public ActionResult GetFile(int id)
        {
            using (var logFile = new StreamWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["FilesPath"], @"FileLog.txt"), true))
            {
                var guid = Guid.NewGuid().ToString();

                logFile.WriteLine("Guid : {0} | File request accepted | Date : {1:H:mm:ss zzz dd/mm/yy } | Id: {2}", guid, DateTime.Now, id);

                try
                {
                    using (var context = new InnostarModelsContext())
                    {
                        var datafileRepository = new DataFileRepository(context);
                        var dataFiles          = datafileRepository._All.Where(e => e.Id == id);
                        //GetBy(new Query<DataFile>(e => e.Id == id));
                        if (dataFiles.Any())
                        {
                            var    dataFile = dataFiles.FirstOrDefault();
                            string path     = Path.Combine(
                                AppDomain.CurrentDomain.BaseDirectory,
                                ConfigurationManager.AppSettings["FilesPath"],
                                dataFile.LocalFileName);
                            if (System.IO.File.Exists(path))
                            {
                                //logFile.WriteLine("Guid : {0} | File sent | Date : {1:H:mm:ss zzz dd/mm/yy } | Filename: {2}", guid, DateTime.Now, dataFile.OriginalFileName);
                                return(base.File(path, GetContentType(path)));
                            }
                            else
                            {
                                //logFile.WriteLine("Guid : {0} | No file at disc | Date : {1:H:mm:ss zzz dd/mm/yy }", guid, DateTime.Now);
                                return(new HttpStatusCodeResult(404, "no such file"));
                            }
                        }
                        else
                        {
                            //logFile.WriteLine(
                            //    "Guid : {0} | No file in DB | Date : {1:H:mm:ss zzz dd/mm/yy }",
                            //    guid,
                            //    DateTime.Now);
                            return(new HttpStatusCodeResult(404, "no such file"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    //logFile.WriteLine("Guid : {0} | File sending exception| Date : {1:H:mm:ss zzz dd/mm/yy } | Exception: {2}", guid, DateTime.Now, ex.Message);
                    return(new HttpStatusCodeResult(500, "server error"));
                }
            }
        }
コード例 #7
0
        public JsonResult _MessageVariables(string login)
        {
            var receiverStrings = login.Split('@');
            var xmppLogin       = receiverStrings[0];

            using (var context = new InnostarModelsContext())
            {
                var result = new Dictionary <string, string>();

                var repository = new ChatUserRepository(context);
                var users      = repository._Get(e => e.XmppLogin == xmppLogin).ToList();

                if (users.Any())
                {
                    var user  = users.FirstOrDefault();
                    var email = string.IsNullOrEmpty(user.Email) ? string.Empty : user.Email;
                    var name  = string.IsNullOrEmpty(user.Name) ? user.Login : user.Name;

                    result.Add("userEmail", email);
                    result.Add("userDisplayName", name);


                    var requestRepository = new RecoverPasswordRequestRepository(context);
                    var requests          =
                        requestRepository._Get(e => e.UserId == user.Id)
                        .OrderByDescending(e => e.RequestAcceptedTime)
                        .ToList();

                    var request = requests.Any() ? GetRecoverLink(requests.FirstOrDefault().RequestKey) : string.Empty;
                    result.Add("userPasswordRequest", request);

                    var confirmEmailRepository = new ConfirmEmailRequestRepository(context);
                    var confirmEmailrequests   =
                        confirmEmailRepository._Get(e => e.UserId == user.Id)
                        .OrderByDescending(e => e.RequestAcceptedTime)
                        .ToList();

                    var confirmEmailrequest = confirmEmailrequests.Any() ? GetConfirmLink(confirmEmailrequests.FirstOrDefault().RequestKey) : string.Empty;
                    result.Add("userConfirmRequest", confirmEmailrequest);
                }
                else
                {
                    result.Add("userEmail", string.Empty);
                    result.Add("userDisplayName", string.Empty);
                    result.Add("userRequest", string.Empty);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #8
0
        public string _GenerateRecoverLink(string login)
        {
            var receiverStrings = login.Split('@');
            var xmppLogin       = receiverStrings[0];

            using (var context = new InnostarModelsContext())
            {
                var repository = new ChatUserRepository(context);
                var users      = repository._Get(e => e.XmppLogin == xmppLogin).ToList();

                if (users.Any())
                {
                    var user = users.FirstOrDefault();

                    var rnd        = new Random();
                    var requestKey = rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                     + Guid.NewGuid().ToString().Replace("-", string.Empty)
                                     + rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                     + Guid.NewGuid().ToString().Replace("-", string.Empty);

                    var newPassword = rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                      + Guid.NewGuid().ToString().Replace("-", string.Empty)
                                      + rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                      + Guid.NewGuid().ToString().Replace("-", string.Empty);

                    var pu = new PasswordUtility(newPassword.ToCharArray());
                    user.PasswordHash = pu.Hash;
                    user.PasswordSalt = pu.Salt;

                    //repository._Update(user);
                    //repository._Save();

                    var recoverRepository = new RecoverPasswordRequestRepository(context);

                    var request = new RecoverPasswordRequest
                    {
                        IsActive            = true,
                        RequestAcceptedTime = DateTime.Now,
                        RequestKey          = requestKey,
                        User = user
                    };

                    recoverRepository._Insert(request);
                    recoverRepository._Save();
                }
            }

            return(string.Empty);
        }
コード例 #9
0
        public ActionResult Delete(int id)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var template   = repository._Get(e => e.Id == id).FirstOrDefault();

                if (!template.Blocked)
                {
                    repository._Delete(template);
                    repository._Save();
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public ActionResult ConfirmEmail(string key)
        {
            using (var dataContext = new InnostarModelsContext())
            {
                var repository = new ConfirmEmailRequestRepository(dataContext);

                var requests = repository._Get(u => u.RequestKey.Equals(key) && u.IsActive).ToList();

                if (requests.Any())
                {
                    var request = requests.FirstOrDefault();

                    if (request == null)
                    {
                        throw new Exception("Данного запроса не существует");
                    }

                    var userRepository = new ChatUserRepository(dataContext);
                    var user           = userRepository._Get(e => e.Id == request.UserId).FirstOrDefault();

                    if (user == null)
                    {
                        throw new Exception("Произошла ошибка в обработке запроса. Обратитесь в службу поддержки");
                    }

                    user.Disabled = false;
                    userRepository._Update(user);
                    userRepository._Save();

                    request.IsActive = false;
                    repository._Update(request);
                    repository._Save();

                    return(View(new ConfirmEmailModel
                    {
                        RequestId = request.Id,
                        RequestKey = key,
                        UserDisplayName = user.Name
                    }));
                }
                else
                {
                    return(RedirectToAction("NotFound", "Error"));
                }
            }
        }
コード例 #11
0
        public string _TextTemplate(int id)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var template   = repository._Get(e => e.Id == id).ToList();

                if (template.Any())
                {
                    return(template.FirstOrDefault().Message);
                }
                else
                {
                    return(string.Empty);
                }
            }
        }
コード例 #12
0
        public ActionResult Create(MessageTemplateViewModel model)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var template   = new MessageTemplate
                {
                    Blocked         = false,
                    SpecialTemplate = 0,
                    Message         = model.Text,
                    Title           = model.Title
                };

                repository._Insert(template);
                repository._Save();
            }

            return(RedirectToAction("Index"));
        }
コード例 #13
0
        private IEnumerable <SelectListItem> GetMessageTemplates()
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var templates  = repository._All.Where(e => e.SpecialTemplate == 0).ToList();
                var result     = new List <SelectListItem>();
                foreach (var template in templates)
                {
                    result.Add(new SelectListItem
                    {
                        Text  = template.Title,
                        Value = template.Id.ToString(CultureInfo.InvariantCulture)
                    });
                }

                return(result);
            }
        }
コード例 #14
0
        public string DisableSafeMode(int id)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new ChatUserRepository(context);
                var users      = repository._Get(e => e.Id == id).ToList();

                if (users.Any())
                {
                    var user = users.FirstOrDefault();
                    user.SafeModeActivated = false;
                    user.SafeModeEndDate   = DateTime.Now;

                    repository._Update(user);
                    repository._Save();
                }
            }

            return(string.Empty);
        }
コード例 #15
0
        public ActionResult Edit(MessageTemplateViewModel model)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var template   = repository._Get(e => e.Id == model.Id).FirstOrDefault();

                template.Message = model.Text;

                if (!model.Blocked)
                {
                    template.Title = model.Title;
                }

                repository._Update(template);
                repository._Save();
            }

            return(RedirectToAction("Index"));
        }
コード例 #16
0
        public ActionResult Password(RecoverPasswordModel requestModel)
        {
            using (var dataContext = new InnostarModelsContext())
            {
                var recoverRepository = new RecoverPasswordRequestRepository(dataContext);

                var request = recoverRepository._Get(u => u.Id == requestModel.RequestId &&
                                                     u.RequestKey == requestModel.RequestKey &&
                                                     u.IsActive).FirstOrDefault();


                if (request == null)
                {
                    throw new Exception("Данного запроса не существует");
                }

                var userRepository = new ChatUserRepository(dataContext);
                var user           = userRepository._Get(e => e.Id == request.UserId).FirstOrDefault();

                if (user == null)
                {
                    throw new Exception("Произошла ошибка в обработке запроса. Обратитесь в службу поддержки");
                }

                if (!string.IsNullOrEmpty(requestModel.NewPassword))
                {
                    var pu = new PasswordUtility(requestModel.NewPassword.ToCharArray());
                    user.PasswordHash = pu.Hash;
                    user.PasswordSalt = pu.Salt;
                }

                userRepository._Update(user);
                userRepository._Save();

                //request.IsActive = false;
                //recoverRepository.Update(request);
                //recoverRepository.Save();

                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #17
0
        public ActionResult Index()
        {
            using (var context = new InnostarModelsContext())
            {
                var repository     = new ChatUserRepository(context);
                int countAllUsers  = repository._All.Count();
                int countSafeUsers = repository._All.Count(user => user.SafeModeActivated);

                return(View(new StatisticsViewModel
                {
                    ActiveUserNumber = 0,
                    SafeUserNumber = countSafeUsers,
                    UserNumber = countAllUsers,
                    XmppAdminLogin =
                        ConfigurationManager.AppSettings["XmppAdminLogin"] + "@" +
                        ConfigurationManager.AppSettings["XmppServerName"],
                    XmppAdminPassword = ConfigurationManager.AppSettings["XmppAdminPassword"],
                    HttpBindAddress = ConfigurationManager.AppSettings["httpBindAdress"]
                }));
            }
        }
コード例 #18
0
        public string _GenerateConfirmLink(string login)
        {
            var receiverStrings = login.Split('@');
            var xmppLogin       = receiverStrings[0];

            using (var context = new InnostarModelsContext())
            {
                var repository = new ChatUserRepository(context);
                var users      = repository._Get(e => e.XmppLogin == xmppLogin).ToList();

                if (users.Any())
                {
                    var user = users.FirstOrDefault();

                    var confirmRepository = new ConfirmEmailRequestRepository(context);
                    var rnd        = new Random();
                    var requestKey = rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                     + Guid.NewGuid().ToString().Replace("-", string.Empty)
                                     + rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                     + Guid.NewGuid().ToString().Replace("-", string.Empty);

                    //user.Disabled = true;
                    //repository._Update(user);
                    //repository._Save();

                    var request = new ConfirmEmailRequest
                    {
                        IsActive            = true,
                        RequestAcceptedTime = DateTime.Now,
                        RequestKey          = requestKey,
                        User = user
                    };

                    confirmRepository._Insert(request);
                    confirmRepository._Save();
                }
            }

            return(string.Empty);
        }
コード例 #19
0
        public ActionResult GetAllXmppLogins(bool?safeMode = false)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new ChatUserRepository(context);
                var chatLogins = new string[2];
                if (safeMode.Value)
                {
                    chatLogins = repository._All.Where(e => e.SafeModeActivated && !e.Disabled).Select(e => e.XmppLogin).ToArray();
                }
                else
                {
                    chatLogins = repository._All.Where(e => !e.Disabled).Select(e => e.XmppLogin).ToArray();
                    for (int i = 0; i != chatLogins.Length; i++)
                    {
                        chatLogins[i] += "@" + ConfigurationManager.AppSettings["XmppServerName"];
                    }
                }

                return(Json(chatLogins, JsonRequestBehavior.AllowGet));
            }
        }