This commit is contained in:
20
Yavsc/ViewModels/Account/ChangePasswordBindingModel.cs
Normal file
20
Yavsc/ViewModels/Account/ChangePasswordBindingModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Models.Account {
|
||||
public class ChangePasswordBindingModel {
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string OldPassword { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string NewPassword { get; set; }
|
||||
}
|
||||
public class SetPasswordBindingModel {
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string NewPassword { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class ExternalLoginConfirmationViewModel
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
|
||||
}
|
||||
}
|
12
Yavsc/ViewModels/Account/ForgotPasswordViewModel.cs
Normal file
12
Yavsc/ViewModels/Account/ForgotPasswordViewModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class ForgotPasswordViewModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
}
|
29
Yavsc/ViewModels/Account/LoginViewModel.cs
Executable file
29
Yavsc/ViewModels/Account/LoginViewModel.cs
Executable file
@ -0,0 +1,29 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class LoginViewModel
|
||||
{
|
||||
[Required]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Display(Name = "Remember me?")]
|
||||
public bool RememberMe { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This value indicates the OAuth client method recieving the code,
|
||||
/// in case of.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ReturnUrl { get; set; }
|
||||
|
||||
public IEnumerable<AuthenticationDescription> ExternalProviders { get; set; }
|
||||
}
|
||||
}
|
28
Yavsc/ViewModels/Account/RegisterViewModel.cs
Normal file
28
Yavsc/ViewModels/Account/RegisterViewModel.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class RegisterViewModel
|
||||
{
|
||||
[Required]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[Display(Name = "Email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "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 GoogleRegId { get; set; }
|
||||
}
|
||||
}
|
23
Yavsc/ViewModels/Account/ResetPasswordViewModel.cs
Normal file
23
Yavsc/ViewModels/Account/ResetPasswordViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class ResetPasswordViewModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} 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; }
|
||||
}
|
||||
}
|
16
Yavsc/ViewModels/Account/SendCodeViewModel.cs
Normal file
16
Yavsc/ViewModels/Account/SendCodeViewModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class SendCodeViewModel
|
||||
{
|
||||
public string SelectedProvider { get; set; }
|
||||
|
||||
public ICollection<SelectListItem> Providers { get; set; }
|
||||
|
||||
public string ReturnUrl { get; set; }
|
||||
|
||||
public bool RememberMe { get; set; }
|
||||
}
|
||||
}
|
8
Yavsc/ViewModels/Account/UnregisterViewModel.cs
Normal file
8
Yavsc/ViewModels/Account/UnregisterViewModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class UnregisterViewModel
|
||||
{
|
||||
public string ReturnUrl { get; set; }
|
||||
|
||||
}
|
||||
}
|
21
Yavsc/ViewModels/Account/VerifyCodeViewModel.cs
Normal file
21
Yavsc/ViewModels/Account/VerifyCodeViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Account
|
||||
{
|
||||
public class VerifyCodeViewModel
|
||||
{
|
||||
[Required]
|
||||
public string Provider { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Code { get; set; }
|
||||
|
||||
public string ReturnUrl { get; set; }
|
||||
|
||||
[Display(Name = "Remember this browser?")]
|
||||
public bool RememberBrowser { get; set; }
|
||||
|
||||
[Display(Name = "Remember me?")]
|
||||
public bool RememberMe { get; set; }
|
||||
}
|
||||
}
|
143
Yavsc/ViewModels/Auth/AuthorisationHandlers.cs
Normal file
143
Yavsc/ViewModels/Auth/AuthorisationHandlers.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc {
|
||||
public class PrivateChatEntryRequirement : IAuthorizationRequirement
|
||||
{
|
||||
}
|
||||
|
||||
public class EditRequirement : IAuthorizationRequirement
|
||||
{
|
||||
public EditRequirement()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSpotInfo : IAuthorizationRequirement
|
||||
{
|
||||
public DirectoryInfo PathInfo { get; private set; }
|
||||
public FileSpotInfo(string path, Blog b) {
|
||||
PathInfo = new DirectoryInfo(path);
|
||||
AuthorId = b.AuthorId;
|
||||
BlogEntryId = b.Id;
|
||||
}
|
||||
public string AuthorId { get; private set; }
|
||||
public long BlogEntryId { get; private set; }
|
||||
|
||||
}
|
||||
public class ViewRequirement : IAuthorizationRequirement
|
||||
{
|
||||
public ViewRequirement()
|
||||
{
|
||||
}
|
||||
}
|
||||
public class BlogEditHandler : AuthorizationHandler<EditRequirement, Blog>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, Blog resource)
|
||||
{
|
||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.AuthorId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
public class PostUserFileHandler : AuthorizationHandler<EditRequirement, FileSpotInfo>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, FileSpotInfo resource)
|
||||
{
|
||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName)
|
||||
|| context.User.IsInRole(Constants.AdminGroupName))
|
||||
context.Succeed(requirement);
|
||||
if (!context.User.Identity.IsAuthenticated)
|
||||
context.Fail();
|
||||
if (resource.AuthorId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
else context.Fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class BlogViewHandler : AuthorizationHandler<ViewRequirement, Blog>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, Blog resource)
|
||||
{
|
||||
if (context.User.IsInRole("Moderator"))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.AuthorId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
else if (resource.visible)
|
||||
// TODO && ( resource.Circles == null || context.User belongs to resource.Circles )
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandViewHandler : AuthorizationHandler<ViewRequirement, Command>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, Command resource)
|
||||
{
|
||||
if (context.User.IsInRole("FrontOffice"))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.ClientId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
else if (resource.PerformerId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
public class CommandEditHandler : AuthorizationHandler<EditRequirement, Command>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, Command resource)
|
||||
{
|
||||
if (context.User.IsInRole("FrontOffice"))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.ClientId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
public class HasTemporaryPassHandler : AuthorizationHandler<PrivateChatEntryRequirement>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, PrivateChatEntryRequirement requirement)
|
||||
{
|
||||
if (!context.User.HasClaim(c => c.Type == "TemporaryBadgeExpiry" &&
|
||||
c.Issuer == Constants.Issuer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var temporaryBadgeExpiry =
|
||||
Convert.ToDateTime(context.User.FindFirst(
|
||||
c => c.Type == "TemporaryBadgeExpiry" &&
|
||||
c.Issuer == Constants.Issuer).Value);
|
||||
|
||||
if (temporaryBadgeExpiry > DateTime.Now)
|
||||
{
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class HasBadgeHandler : AuthorizationHandler<PrivateChatEntryRequirement>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, PrivateChatEntryRequirement requirement)
|
||||
{
|
||||
if (!context.User.HasClaim(c => c.Type == "BadgeNumber" &&
|
||||
c.Issuer == Constants.Issuer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
11
Yavsc/ViewModels/Auth/AuthorisationView.cs
Normal file
11
Yavsc/ViewModels/Auth/AuthorisationView.cs
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
public class AuthorisationView {
|
||||
public OpenIdConnectMessage Message { get; set; }
|
||||
public Application Application { get; set; }
|
||||
}
|
||||
}
|
12
Yavsc/ViewModels/Auth/ClaimTypes.cs
Normal file
12
Yavsc/ViewModels/Auth/ClaimTypes.cs
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
namespace Yavsc {
|
||||
|
||||
|
||||
internal static class YavscClaimTypes {
|
||||
|
||||
public const string GoogleUserId = "GoogleUserId";
|
||||
}
|
||||
|
||||
}
|
11
Yavsc/ViewModels/Calendar/SetGoogleCalendarViewModel.cs
Normal file
11
Yavsc/ViewModels/Calendar/SetGoogleCalendarViewModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
namespace Yavsc.ViewModels.Calendar
|
||||
{
|
||||
public class SetGoogleCalendarViewModel
|
||||
{
|
||||
public string GoogleCalendarId { get; set; }
|
||||
|
||||
public string ReturnUrl { get; set; }
|
||||
}
|
||||
|
||||
}
|
7
Yavsc/ViewModels/Calendar/UpcomingEventsViewModel.cs
Normal file
7
Yavsc/ViewModels/Calendar/UpcomingEventsViewModel.cs
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
namespace Yavsc.ViewModels.Calendar {
|
||||
public class UpcomingEventsViewModel {
|
||||
|
||||
}
|
||||
|
||||
}
|
12
Yavsc/ViewModels/Manage/AddPhoneNumberViewModel.cs
Normal file
12
Yavsc/ViewModels/Manage/AddPhoneNumberViewModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class AddPhoneNumberViewModel
|
||||
{
|
||||
[Required]
|
||||
[Phone]
|
||||
[Display(Name = "Phone number")]
|
||||
public string PhoneNumber { get; set; }
|
||||
}
|
||||
}
|
23
Yavsc/ViewModels/Manage/ChangePasswordViewModel.cs
Normal file
23
Yavsc/ViewModels/Manage/ChangePasswordViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class ChangePasswordViewModel
|
||||
{
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Current password")]
|
||||
public string OldPassword { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "New password")]
|
||||
public string NewPassword { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm new password")]
|
||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
}
|
||||
}
|
13
Yavsc/ViewModels/Manage/ChangeUserNameViewModel.cs
Normal file
13
Yavsc/ViewModels/Manage/ChangeUserNameViewModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class ChangeUserNameViewModel
|
||||
{
|
||||
[Required]
|
||||
[Display(Name = "New user name"),RegularExpression(Constants.UserNameRegExp)]
|
||||
public string NewUserName { get; set; }
|
||||
|
||||
}
|
||||
}
|
12
Yavsc/ViewModels/Manage/ConfigureTwoFactorViewModel.cs
Normal file
12
Yavsc/ViewModels/Manage/ConfigureTwoFactorViewModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class ConfigureTwoFactorViewModel
|
||||
{
|
||||
public string SelectedProvider { get; set; }
|
||||
|
||||
public ICollection<SelectListItem> Providers { get; set; }
|
||||
}
|
||||
}
|
7
Yavsc/ViewModels/Manage/FactorViewModel.cs
Normal file
7
Yavsc/ViewModels/Manage/FactorViewModel.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class FactorViewModel
|
||||
{
|
||||
public string Purpose { get; set; }
|
||||
}
|
||||
}
|
31
Yavsc/ViewModels/Manage/IndexViewModel.cs
Normal file
31
Yavsc/ViewModels/Manage/IndexViewModel.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class IndexViewModel
|
||||
{
|
||||
public string UserName {get; set; }
|
||||
|
||||
public bool HasPassword { get; set; }
|
||||
|
||||
public IList<UserLoginInfo> Logins { get; set; }
|
||||
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
public bool TwoFactor { get; set; }
|
||||
|
||||
public bool BrowserRemembered { get; set; }
|
||||
|
||||
public Activity Activity { get; set; }
|
||||
|
||||
public long PostsCounter { get; set; }
|
||||
|
||||
public AccountBalance Balance { get; set; }
|
||||
|
||||
public long ActiveCommandCount { get; set; }
|
||||
|
||||
public bool HasDedicatedCalendar { get; set; }
|
||||
}
|
||||
}
|
13
Yavsc/ViewModels/Manage/ManageLoginsViewModel.cs
Normal file
13
Yavsc/ViewModels/Manage/ManageLoginsViewModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.Identity;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class ManageLoginsViewModel
|
||||
{
|
||||
public IList<UserLoginInfo> CurrentLogins { get; set; }
|
||||
|
||||
public IList<AuthenticationDescription> OtherLogins { get; set; }
|
||||
}
|
||||
}
|
8
Yavsc/ViewModels/Manage/RemoveLoginViewModel.cs
Executable file
8
Yavsc/ViewModels/Manage/RemoveLoginViewModel.cs
Executable file
@ -0,0 +1,8 @@
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class RemoveLoginViewModel
|
||||
{
|
||||
public string LoginProvider { get; set; }
|
||||
public string ProviderKey { get; set; }
|
||||
}
|
||||
}
|
18
Yavsc/ViewModels/Manage/SetPasswordViewModel.cs
Normal file
18
Yavsc/ViewModels/Manage/SetPasswordViewModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class SetPasswordViewModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "New password")]
|
||||
public string NewPassword { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm new password")]
|
||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
}
|
||||
}
|
15
Yavsc/ViewModels/Manage/VerifyPhoneNumberViewModel.cs
Normal file
15
Yavsc/ViewModels/Manage/VerifyPhoneNumberViewModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ViewModels.Manage
|
||||
{
|
||||
public class VerifyPhoneNumberViewModel
|
||||
{
|
||||
[Required]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Required]
|
||||
[Phone]
|
||||
[Display(Name = "Phone number")]
|
||||
public string PhoneNumber { get; set; }
|
||||
}
|
||||
}
|
11
Yavsc/ViewModels/UserFiles/BlogFilesPost.cs
Normal file
11
Yavsc/ViewModels/UserFiles/BlogFilesPost.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
public class BlogFilesPost {
|
||||
[Required]
|
||||
public long PostId {get; set; }
|
||||
[Required]
|
||||
public IList<IFormFile> File { get; set; }
|
||||
}
|
19
Yavsc/ViewModels/UserFiles/FileInfo.cs
Normal file
19
Yavsc/ViewModels/UserFiles/FileInfo.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.ViewModels
|
||||
{
|
||||
public class FileInfo
|
||||
{
|
||||
|
||||
public string PermanentUri { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public int Size { get; set; }
|
||||
|
||||
public DateTime Creation { get; set; }
|
||||
|
||||
public string MimeType { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user