Skip to content
Merged

Auth #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .idea/.idea.Web-Series-API--ASP.NET/.idea/git_toolbox_prj.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 58 additions & 5 deletions .idea/.idea.Web-Series-API--ASP.NET/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions BusinessEntityLayer/BusinessEntityLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ArchiveModel.cs" />
<Compile Include="AuthModel.cs" />
<Compile Include="TokenModel.cs" />
<Compile Include="CategoryModel.cs" />
<Compile Include="ExpansModel.cs" />
<Compile Include="FeaturedVideoModel.cs" />
Expand All @@ -55,7 +55,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SalaryModel.cs" />
<Compile Include="SubscriptionModel.cs" />
<Compile Include="UserAuthModel.cs" />
<Compile Include="UserModel.cs" />
<Compile Include="VideoModel.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace BusinessEntityLayer
{
public class AuthModel
public class TokenModel
{
public int Id { get; set; }
public string Token { get; set; }
public string TokenData { get; set; }
public string Device { get; set; }
public string Platfrom { get; set; }
public string Browser { get; set; }
Expand All @@ -20,7 +20,6 @@ public class AuthModel
public Nullable<int> LoginId { get; set; }
public Nullable<int> UserId { get; set; }

public virtual UserModel User { get; set; }
public virtual LoginModel Login { get; set; }
}
}
13 changes: 0 additions & 13 deletions BusinessEntityLayer/UserAuthModel.cs

This file was deleted.

1 change: 1 addition & 0 deletions BusinessLogicLayer/BusinessLogicLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Services\AuthService.cs" />
<Compile Include="Services\LoginService.cs" />
<Compile Include="Services\CategoryService.cs" />
<Compile Include="Services\ExpansService.cs" />
Expand Down
46 changes: 46 additions & 0 deletions BusinessLogicLayer/Services/AuthService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using AutoMapper;
using BusinessEntityLayer;
using DataAccessLayer;
using DataAccessLayer.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLogicLayer.Services
{
public class AuthService
{

public static void Authenticate(LoginModel login)
{
var tokenModel = new TokenModel();
var config = new MapperConfiguration(c => c.CreateMap<LoginModel, Login>());
var mapper = new Mapper(config);
var data = mapper.Map<LoginModel, Login>(login);
var result = DataAccessFactory.AuthDataAccess().Authenticate(data);

if (result != null)
{
tokenModel.TokenData = result.TokenData;
tokenModel.LoginId = result.LoginId;
}
if (result == null)
{
throw new Exception("User not found");
}
}

public static LoginModel EmailCheck(string email)
{
var config = new MapperConfiguration(c =>
{
c.CreateMap<Login, LoginModel>();
});
var mapper = new Mapper(config);
var isFind = mapper.Map<Login, LoginModel>(DataAccessFactory.AuthDataAccess().GetByEmail(email));
return isFind;
}
}
}
20 changes: 0 additions & 20 deletions BusinessLogicLayer/Services/LoginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@ namespace BusinessLogicLayer.Services
{
public class LoginService
{

public static void Authenticate(LoginModel login)
{
var authModel = new AuthModel();
var config = new MapperConfiguration(c => c.CreateMap<LoginModel,Login>());
var mapper = new Mapper(config);
var data = mapper.Map<LoginModel, Login>(login);
var result = DataAccessFactory.AuthDataAccess().Authenticate(data);

if (result != null)
{
authModel.Token = result.Token;
authModel.LoginId = result.LoginId;
}
if (result == null)
{
throw new Exception("User not found");
}
}

public static void Create(LoginModel login)
{
login.Role = "User";
Expand Down
2 changes: 1 addition & 1 deletion DataAccessLayer/App.Config
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
&gt;<connectionStrings><add name="WebSeriesDBEntities" connectionString="metadata=res://*/EntityFramework.WebSeriesDB.csdl|res://*/EntityFramework.WebSeriesDB.ssdl|res://*/EntityFramework.WebSeriesDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=web-series.database.windows.net;initial catalog=WebSeriesDB;user id=livealvi;password=Highme1#;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
<connectionStrings><add name="WebSeriesDBEntities" connectionString="metadata=res://*/EntityFramework.WebSeriesDB.csdl|res://*/EntityFramework.WebSeriesDB.ssdl|res://*/EntityFramework.WebSeriesDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=web-series.database.windows.net;initial catalog=WebSeriesDB;user id=livealvi;password=Highme1#;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
4 changes: 2 additions & 2 deletions DataAccessLayer/DataAccessFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static IRepository<Login, int> LoginDataAccess()
{
return new LoginRepo(db);
}
public static IAuth AuthDataAccess()
public static IAuth<Login, string> AuthDataAccess()
{
return new LoginRepo(db);
return new AuthRepo(db);
}

//User
Expand Down
9 changes: 5 additions & 4 deletions DataAccessLayer/DataAccessLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
<Compile Include="EntityFramework\Archive.cs">
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
<Compile Include="EntityFramework\Auth.cs">
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
<Compile Include="EntityFramework\Category.cs">
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
Expand Down Expand Up @@ -88,6 +85,9 @@
<Compile Include="EntityFramework\Subscription.cs">
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
<Compile Include="EntityFramework\Token.cs">
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
<Compile Include="EntityFramework\User.cs">
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
Expand All @@ -103,8 +103,8 @@
<DependentUpon>WebSeriesDB.Context.tt</DependentUpon>
</Compile>
<Compile Include="EntityFramework\WebSeriesDB.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>WebSeriesDB.tt</DependentUpon>
</Compile>
<Compile Include="EntityFramework\WebSeriesDB.Designer.cs">
Expand All @@ -119,6 +119,7 @@
<Compile Include="Interfaces\ISubscription.cs" />
<Compile Include="Interfaces\IWatch.cs" />
<Compile Include="Repo\AuthRepo.cs" />
<Compile Include="Repo\TokenRepo.cs" />
<Compile Include="Repo\CategoryRepo.cs" />
<Compile Include="Repo\ExpansRepo.cs" />
<Compile Include="Repo\FeaturedVideoRepo.cs" />
Expand Down
4 changes: 2 additions & 2 deletions DataAccessLayer/EntityFramework/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class Login
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Login()
{
this.Auths = new HashSet<Auth>();
this.Tokens = new HashSet<Token>();
this.Users = new HashSet<User>();
}

Expand All @@ -28,7 +28,7 @@ public Login()
public string Role { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Auth> Auths { get; set; }
public virtual ICollection<Token> Tokens { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<User> Users { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace DataAccessLayer.EntityFramework
using System;
using System.Collections.Generic;

public partial class Auth
public partial class Token
{
public int Id { get; set; }
public string Token { get; set; }
public string TokenData { get; set; }
public string Device { get; set; }
public string Platfrom { get; set; }
public string Browser { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion DataAccessLayer/EntityFramework/WebSeriesDB.Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
}

public virtual DbSet<Archive> Archives { get; set; }
public virtual DbSet<Auth> Auths { get; set; }
public virtual DbSet<Category> Categories { get; set; }
public virtual DbSet<Expans> Expanses { get; set; }
public virtual DbSet<FeaturedVideo> FeaturedVideos { get; set; }
Expand All @@ -36,6 +35,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
public virtual DbSet<Review> Reviews { get; set; }
public virtual DbSet<Salary> Salarys { get; set; }
public virtual DbSet<Subscription> Subscriptions { get; set; }
public virtual DbSet<Token> Tokens { get; set; }
public virtual DbSet<UserRequest> UserRequests { get; set; }
public virtual DbSet<User> Users { get; set; }
public virtual DbSet<Video> Videos { get; set; }
Expand Down
Loading