0

I have a web application.Like blog but it have an membership.Users can register and login.Some User will have Author role and write articles, some users will have Moderator role and etc. Here my some application codes. MyModels;

UserModel.cs:

public class UserModel
{
    public virtual int Id { get; set; }
    public virtual DateTime RegisterDate { get; set; }
    public virtual string RegisterIp { get; set; }
    public virtual string EMail { get; set; }
    public virtual string Password { get; set; }
    public virtual string UserName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual string WebSiteLink { get; set; }
    public virtual string FaceBookLink { get; set; }
    public virtual string TwitterLink { get; set; }
    public virtual string GooglePlusLink { get; set; }
    public virtual string PinterestLink { get; set; }
    public virtual IList<RoleModel> UserRole { get; set; }
    public virtual DateTime LastLogIn { get; set; }
    public virtual string LastLoginIP { get; set; }
    public virtual string About { get; set; }
    public virtual bool IsActive { get; set; }
    public virtual bool IsFreelancer { get; set; }
    public virtual bool IsBanned { get; set; }

    public UserModel()
    {
        UserRole = new List<RoleModel>();
    }

}

RoleModel.cs:

public virtual int Id { get; set; }
    public virtual string RoleName { get; set; }

    public virtual IList<UserModel> UsersInRole { get; set; }

    public RoleModel()
    {
        UsersInRole = new List<UserModel>();
    }

Here is my LoginPartial.cshtml:

<div class="widget categories">
    <h5>Kullanıcı Paneli</h5>
    <br />
    <input type="text" name="userNameInput" placeholder="Kullanıcı adınız..." class="form-control" required />
    <br />
    <input type="password" name="userPasswordInput" placeholder="Şifreniz..." class="form-control" required />
    <br />
    <ul>
        <li><a href="#" type="submit" class="form-control" style="text-align:center">Giriş</a></li>
        <li><a href="/User/NewUser" class="form-control" style="text-align:center">Üye Ol</a></li>
    </ul>
</div>

My login partial is in Master page(_Layout.cshtml).My users can have one role or more roles as you can. Now i need that: User will login from User Panel. When he logged in i need some cookie or token i think. Because after login if user has Author role i'll check it then let him for write an article. If user has moderator role it can be modify articles, make active or deactive articles... How can make an Authentication in my application? Which way should i follow? I need an idea for this issue. Maybe you can see better in page's screenshot which i tried telling.

Translate:

  • Kullanıcı Paneli= User Panel
  • Kullanıdı Adınız(In first textbox) = User Name
  • Şifreniz (In second textbox) = Password
  • Giriş = Login
  • Üye Ol = Register

enter image description here

CoderWho
  • 210
  • 1
  • 5
  • 20
  • 1
    Check this example: http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/ – py3r3str Aug 31 '15 at 09:48
  • @py3r3str i checked your advice. I tried some but i can't do it. Is there any way to more help me for add token authentication to my application? – CoderWho Sep 01 '15 at 08:01

1 Answers1

1

I answered a similar question here.

For the roles management, I also use a LocalStorage or a sessionStorage (localstorage are persisted until explicitly deleted and sessionStorage are available only per windows or tab, see here).

Hope that helps. I can write an example with your code if you need it.

Community
  • 1
  • 1
Hamid Cherif
  • 171
  • 2
  • 14