public string Login(LoginViewModel loginViewModel)
        {
            Throw.IfNullOrEmptyString(loginViewModel.UserName, nameof(loginViewModel.UserName));
            Throw.IfNullOrEmptyString(loginViewModel.Password, nameof(loginViewModel.Password));

            if (!_accountsProvider.UserExists(loginViewModel.UserName))
            {
                return(TranslateHelper.TranslateMessage(DictionaryKeys.Messages.UserNotExists));
            }

            return(_accountsProvider.Login(loginViewModel.UserName, loginViewModel.Password, loginViewModel.StillLoggedIn)
                                ? string.Empty
                                : TranslateHelper.TranslateMessage(DictionaryKeys.Messages.IncorrectPassword));
        }
Пример #2
0
        public bool UploadPhoto(Stream fileStream, string fileName)
        {
            try
            {
                var path = TranslateHelper.TranslateMessage(DictionaryKeys.PhotoSaveTo.Path) + fileName.Split('.')[0];
                using (var memoryStream = new MemoryStream())
                {
                    fileStream.CopyTo(memoryStream);
                    var mediaCreator = new MediaCreator();
                    var options      = new MediaCreatorOptions
                    {
                        Versioned = false,
                        IncludeExtensionInItemName = false,
                        Database    = Context.Database,
                        Destination = path
                    };

                    using (new SecurityDisabler())
                    {
                        var item        = mediaCreator.CreateFromStream(memoryStream, fileName, options);
                        var userProfile = Context.User.Profile;
                        if (userProfile != null)
                        {
                            userProfile.Icon = MediaManager.GetMediaUrl(item);
                            Context.User.Profile.Save();
                        }
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }