Browse Source

9th update

ganahrhr 3 years ago
parent
commit
82e1cf8546

+ 26 - 0
Areas/Identity/Pages/Account/ForgotPassword.cshtml

@@ -0,0 +1,26 @@
+@page
+@model ForgotPasswordModel
+@{
+    ViewData["Title"] = "Забыли свой пароль?";
+}
+
+<h1>@ViewData["Title"]</h1>
+<h4>Введите свой e-mail.</h4>
+<hr />
+<div class="row">
+    <div class="col-md-4">
+        <form method="post">
+            <div asp-validation-summary="All" class="text-danger"></div>
+            <div class="form-group">
+                <label asp-for="Input.Email"></label>
+                <input asp-for="Input.Email" class="form-control" />
+                <span asp-validation-for="Input.Email" class="text-danger"></span>
+            </div>
+            <button type="submit" class="btn btn-primary">Отправить</button>
+        </form>
+    </div>
+</div>
+
+@section Scripts {
+    <partial name="_ValidationScriptsPartial" />
+}

+ 65 - 0
Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs

@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text.Encodings.Web;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace HyperCube.Areas.Identity.Pages.Account
+{
+    [AllowAnonymous]
+    public class ForgotPasswordModel : PageModel
+    {
+        private readonly UserManager<IdentityUser> _userManager;
+
+        public ForgotPasswordModel(UserManager<IdentityUser> userManager)
+        {
+            _userManager = userManager;
+        }
+
+        [BindProperty]
+        public InputModel Input { get; set; }
+
+        public class InputModel
+        {
+            [Required]
+            [EmailAddress]
+            public string Email { get; set; }
+        }
+
+        public async Task<IActionResult> OnPostAsync()
+        {
+            if (ModelState.IsValid)
+            {
+                var user = await _userManager.FindByEmailAsync(Input.Email);
+                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
+                {
+                    // Don't reveal that the user does not exist or is not confirmed
+                    return RedirectToPage("./ForgotPasswordConfirmation");
+                }
+
+                var code = await _userManager.GeneratePasswordResetTokenAsync(user);
+                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+                var callbackUrl = Url.Page(
+                    "/Account/ResetPassword",
+                    pageHandler: null,
+                    values: new { area = "Identity", code, Input.Email },
+                    protocol: Request.Scheme);
+
+                EmailSender emailSender = new();
+                await emailSender.SendEmailAsync(Input.Email, "Сброс пароля",
+                    $"Если вы забыли пароль от своей учетной записи, можно сбросить его по <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>ссылке</a>.");
+
+                return RedirectToPage("./ForgotPasswordConfirmation");
+            }
+
+            return Page();
+        }
+    }
+}

+ 11 - 0
Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml

@@ -0,0 +1,11 @@
+@page
+@model ForgotPasswordConfirmation
+@{
+    ViewData["Title"] = "Сброс пароля";
+}
+
+<h1>@ViewData["Title"]</h1>
+<p>
+    Проверьте свою почту для продолжения процедуры сброса и востановления пароля.    
+</p>
+

+ 16 - 0
Areas/Identity/Pages/Account/ForgotPasswordConfirmation.cshtml.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace HyperCube.Areas.Identity.Pages.Account
+{
+    [AllowAnonymous]
+    public class ForgotPasswordConfirmation : PageModel
+    {
+        public void OnGet()
+        {
+        }
+    }
+}

+ 26 - 0
Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml

@@ -0,0 +1,26 @@
+@page
+@model ResendEmailConfirmationModel
+@{
+    ViewData["Title"] = "Resend email confirmation";
+}
+
+<h1>@ViewData["Title"]</h1>
+<h4>Enter your email.</h4>
+<hr />
+<div class="row">
+    <div class="col-md-4">
+        <form method="post">
+            <div asp-validation-summary="All" class="text-danger"></div>
+            <div class="form-group">
+                <label asp-for="Input.Email"></label>
+                <input asp-for="Input.Email" class="form-control" />
+                <span asp-validation-for="Input.Email" class="text-danger"></span>
+            </div>
+            <button type="submit" class="btn btn-primary">Resend</button>
+        </form>
+    </div>
+</div>
+
+@section Scripts {
+    <partial name="_ValidationScriptsPartial" />
+}

+ 78 - 0
Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml.cs

@@ -0,0 +1,78 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace HyperCube.Areas.Identity.Pages.Account
+{
+    [AllowAnonymous]
+    public class ResendEmailConfirmationModel : PageModel
+    {
+        private readonly UserManager<IdentityUser> _userManager;
+
+        public ResendEmailConfirmationModel(UserManager<IdentityUser> userManager)
+        {
+            _userManager = userManager;
+        }
+
+        [BindProperty]
+        public InputModel Input { get; set; }
+
+        public class InputModel
+        {
+            [Required]
+            [EmailAddress]
+            public string Email { get; set; }
+        }
+
+        public void OnGet()
+        {
+        }
+
+        public async Task<IActionResult> OnPostAsync()
+        {
+            if (!ModelState.IsValid)
+            {
+                return Page();
+            }
+
+            var user = await _userManager.FindByEmailAsync(Input.Email);
+            if (user == null)
+            {
+                ModelState.AddModelError(string.Empty, "Пользователь не найден или подверждение не требуется.");
+                return Page();
+            }
+
+            bool confirmed = await _userManager.IsEmailConfirmedAsync(user);
+            if (confirmed)
+            {
+                ModelState.AddModelError(string.Empty, "Пользователь не найден или подверждение не требуется.");
+                return Page();
+            }
+
+            var userId = await _userManager.GetUserIdAsync(user);
+            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
+            code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
+            var callbackUrl = Url.Page(
+                "/Account/ConfirmEmail",
+                pageHandler: null,
+                values: new { userId = userId, code = code },
+                protocol: Request.Scheme);
+
+            EmailSender emailSender = new();
+            await emailSender.SendEmailAsync(Input.Email, "Подтверждение регистрации",
+                $"Подтвердите регистрацию, пройдя по <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>ссылке</a>.");
+
+            ModelState.AddModelError(string.Empty, "Письмо с подтверждением отправлено, проверьте почту.");
+            return Page();
+        }
+    }
+}

+ 37 - 0
Areas/Identity/Pages/Account/ResetPassword.cshtml

@@ -0,0 +1,37 @@
+@page
+@model ResetPasswordModel
+@{
+    ViewData["Title"] = "Сброс пароля";
+}
+
+<h1>@ViewData["Title"]</h1>
+<h4>Укажите новый пароль.</h4>
+<hr />
+<div class="row">
+    <div class="col-md-4">
+        <form method="post">
+            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
+            <input asp-for="Input.Code" type="hidden" />
+            <div class="form-group">
+                <label asp-for="Input.Email"></label>
+                <input asp-for="Input.Email" class="form-control" />
+                <span asp-validation-for="Input.Email" class="text-danger"></span>
+            </div>
+            <div class="form-group">
+                <label asp-for="Input.Password"></label>
+                <input asp-for="Input.Password" class="form-control" />
+                <span asp-validation-for="Input.Password" class="text-danger"></span>
+            </div>
+            <div class="form-group">
+                <label asp-for="Input.ConfirmPassword"></label>
+                <input asp-for="Input.ConfirmPassword" class="form-control" />
+                <span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
+            </div>
+            <button type="submit" class="btn btn-primary">Сбросить</button>
+        </form>
+    </div>
+</div>
+
+@section Scripts {
+    <partial name="_ValidationScriptsPartial" />
+}

+ 94 - 0
Areas/Identity/Pages/Account/ResetPassword.cshtml.cs

@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.AspNetCore.WebUtilities;
+
+namespace HyperCube.Areas.Identity.Pages.Account
+{
+    [AllowAnonymous]
+    public class ResetPasswordModel : PageModel
+    {
+        private readonly UserManager<IdentityUser> _userManager;
+
+        public ResetPasswordModel(UserManager<IdentityUser> userManager)
+        {
+            _userManager = userManager;
+        }
+
+        [BindProperty]
+        public InputModel Input { get; set; }
+
+        public class InputModel
+        {
+            [Required]
+            [EmailAddress]
+            public string Email { get; set; }
+
+            [Required]
+            [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
+            [DataType(DataType.Password)]
+            public string Password { get; set; }
+
+            [DataType(DataType.Password)]
+            [Display(Name = "Confirm password")]
+            [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
+            public string ConfirmPassword { get; set; }
+
+            public string Code { get; set; }
+        }
+
+        public IActionResult OnGet(string code = null, string email = null)
+        {
+            if (code == null)
+            {
+                return BadRequest("A code must be supplied for password reset.");
+            }
+            else
+            {
+                Input = new InputModel
+                {
+                    Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code))
+                };
+
+                if (email != null)
+                    Input.Email = email;
+
+                return Page();
+            }
+        }
+
+        public async Task<IActionResult> OnPostAsync()
+        {
+            if (!ModelState.IsValid)
+            {
+                return Page();
+            }
+
+            var user = await _userManager.FindByEmailAsync(Input.Email);
+            if (user == null)
+            {
+                // Don't reveal that the user does not exist
+                return RedirectToPage("./ResetPasswordConfirmation");
+            }
+
+            var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);
+            if (result.Succeeded)
+            {
+                return RedirectToPage("./ResetPasswordConfirmation");
+            }
+
+            foreach (var error in result.Errors)
+            {
+                ModelState.AddModelError(string.Empty, error.Description);
+            }
+            return Page();
+        }
+    }
+}

+ 10 - 0
Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml

@@ -0,0 +1,10 @@
+@page
+@model ResetPasswordConfirmationModel
+@{
+    ViewData["Title"] = "Пароль сброшен";
+}
+
+<h1>@ViewData["Title"]</h1>
+<p>
+    Ваш пароль был сброшен. Пожалуйста, <a asp-page="./Login">перейдите поссылке для авторизации</a>.
+</p>

+ 18 - 0
Areas/Identity/Pages/Account/ResetPasswordConfirmation.cshtml.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace HyperCube.Areas.Identity.Pages.Account
+{
+    [AllowAnonymous]
+    public class ResetPasswordConfirmationModel : PageModel
+    {
+        public void OnGet()
+        {
+
+        }
+    }
+}

+ 9 - 7
Models/ArticleModel.cs

@@ -10,11 +10,13 @@ namespace HyperCube.Models
     public enum ArticleStatus {
         [Display(Name = "Новая")]
         New = 0,
-        [Display(Name = "Добавлена")]
-        Added,
-        [Display(Name = "Отредактирована")]
-        Edited,
-        [Display(Name = "Проверена")]
+        [Display(Name = "Сохранена")]
+        Saved,
+        [Display(Name = "Ожидает верификации")]
+        AwatingVerify,
+        [Display(Name = "Верифицируется")]
+        Verifying,
+        [Display(Name = "Верифицирована")]
         Verified,
         [Display(Name = "Отклонена")]
         Rejected,
@@ -25,7 +27,7 @@ namespace HyperCube.Models
     {
         public int ID { get; set; }
         public string Filename { get; set; }
-        public string FileHashSum { get; set; }
+        public string HashSum { get; set; }
         public string FilenameReal { get { return ID + "_" + Filename; } }
         [Required]        
         public string Name { get; set; }        
@@ -92,7 +94,7 @@ namespace HyperCube.Models
                 string stringSQL = $"SELECT acc_id " +
                     $"FROM articles " +
                     $"JOIN actions_history ON actions_history.article_id = articles.id " +
-                    $"WHERE articles.id={this.ID} AND action_type={(int)ArticleStatus.Added}";
+                    $"WHERE articles.id={this.ID} AND action_type={(int)ArticleStatus.Saved}";
 
                 initiatorUUID = await dbCon.SQLSelectUUID(stringSQL);
                 //dbCon.Close();                

+ 2 - 9
Pages/Desktop.razor.cs

@@ -51,12 +51,7 @@ namespace HyperCube.Pages
         ArticleModel _articleClone = new();
         ArticleModel _article = new();
 
-        protected override async Task OnInitializedAsync()
-        {
-            /// refreshing articles
-            await AppData.LoadArticles();
-        }
-
+        protected override async Task OnInitializedAsync() => await AppData.LoadArticles();
         protected override void OnAfterRender(bool firstRender) => _counter = 1;
 
         void SwitchDesktopTab(int tabIndex)
@@ -117,7 +112,7 @@ namespace HyperCube.Pages
                 {
                     _articleClone = DocParse.ReadPDF(_memoryStream);
                     _articleClone.Filename = file.Name;
-                    _articleClone.FileHashSum = hash;
+                    _articleClone.HashSum = hash;
                     _article = (ArticleModel)_articleClone.Clone();
 
                     ReportModel report = _appData.Report;
@@ -184,8 +179,6 @@ namespace HyperCube.Pages
                     Console.WriteLine($"fullpath: {fullpath}");
                     File.WriteAllBytes(fullpath, Encoding.UTF8.GetBytes(html));
 
-                    //NavigationManager.NavigateTo(fullpath, true);
-
                     Console.WriteLine($"Initializing SDK Pullenti ver {Pullenti.Sdk.Version} ({Pullenti.Sdk.VersionDate})... ");
                     Pullenti.Sdk.InitializeAll();
                     //Console.WriteLine($"OK (by ... ms), version {Pullenti.Ner.ProcessorService.Version}");

+ 3 - 3
Pages/DocEdit.razor.cs

@@ -149,7 +149,7 @@ namespace HyperCube.Pages
                 stringSQL = $"UPDATE articles " +
                     $"SET filename='{article.Filename}', article_name='{article.Name}', authors='{article.Authors}', " +
                         $"date_publish='{article.PublishDate:yyyy-MM-dd}', annotation='{article.Annotation}', " +
-                        $"keywords='{article.Keywords}', rating={article.Rating}, file_hash='{article.FileHashSum}' " +
+                        $"keywords='{article.Keywords}', rating={article.Rating}, file_hash='{article.HashSum}' " +
                     $"WHERE id={DocID}";
                 await dbCon.SQLInsert(stringSQL);
             }
@@ -157,7 +157,7 @@ namespace HyperCube.Pages
             {
                 stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords, file_hash) " +
                     $"VALUES ('{article.Filename}', '{article.Name}', '{article.Authors}', '{article.PublishDate:yyyy-MM-dd}'," +
-                        $"'{article.Annotation}', '{article.Keywords}', '{article.FileHashSum}')";
+                        $"'{article.Annotation}', '{article.Keywords}', '{article.HashSum}')";
                 id = await dbCon.SQLInsert(stringSQL);
                 NewProjectSmopp(id);
             }          
@@ -244,7 +244,7 @@ namespace HyperCube.Pages
                 {
                     articleClone = DocParse.ReadPDF(memoryStream);
                     articleClone.Filename = file.Name;
-                    articleClone.FileHashSum = hash;
+                    articleClone.HashSum = hash;
                     article = (ArticleModel)articleClone.Clone();
 
                     IsSubmitDisabled = false;

+ 1 - 1
Properties/PublishProfiles/FolderProfile.pubxml.user

@@ -5,6 +5,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <_PublishTargetUrl>D:\Новая папка</_PublishTargetUrl>
-    <History>True|2021-03-16T15:23:14.9646617Z;</History>
+    <History>True|2021-11-11T15:13:20.6123331Z;True|2021-03-16T18:23:14.9646617+03:00;</History>
   </PropertyGroup>
 </Project>