Пример #1
0
        public IAuthenticationResponse LogIn(ILogIn model, HttpRequestBase request)
        {
            IAuthenticationResponse response = _factory.Create<IAuthenticationResponse>();
            try
            {
                if (model.Email == "*****@*****.**" && model.Password == "test")
                {
                    Claim[] claims = { new Claim(ClaimTypes.Name, "Matt") };
                    ClaimsIdentity identity = new ClaimsIdentity(claims, "ApplicationCookie");
                    IOwinContext ctx = request.GetOwinContext();
                    IAuthenticationManager authManager = ctx.Authentication;
                    authManager.SignIn(identity);
                    response.Success = true;
                    return response;
                }

                response.Success = false;
                response.Error = "Invalid Email and/or Password";
                return response;
            }
            catch (Exception e)
            {
                //TODO: Log;
                response.Success = false;
                response.Error = "Error Logging in";
                return response;
            }
        }
Пример #2
0
 public static string GetUserNickName(HttpRequestBase req)
 {
     var um = req.GetOwinContext().GetUserManager<ApplicationUserManager>();
     var account=um.FindByName(User().Identity.Name);
     if (account == null) return "NaN";
     return account.NickName;
 }
        public void createOwinIdentity(UserAccount user, HttpRequestBase request)
        {
            var identity = new ClaimsIdentity(new[] {
                new Claim(ClaimTypes.Name, user.Username),
            },
            "ApplicationCookie");

            var ctx = request.GetOwinContext();
            var authManager = ctx.Authentication;

            authManager.SignIn(identity);
        }
Пример #4
0
 public IAuthenticationResponse LogOut(HttpRequestBase request)
 {
     IAuthenticationResponse response = _factory.Create<IAuthenticationResponse>();
     try
     {
         IOwinContext ctx = request.GetOwinContext();
         IAuthenticationManager authManager = ctx.Authentication;
         authManager.SignOut("ApplicationCookie");
         response.Success = true;
         return response;
     }
     catch (Exception e)
     {
         //TODO: Log
         response.Success = false;
         response.Error = "Error Logging out";
         return response;
     }
 }
Пример #5
0
 public static async Task<TopicViewModel> GenerateViewModel(HttpRequestBase req,string topicId)
 {
     var context = req.GetOwinContext().Get<ApplicationDbContext>();
     TopicModel topic = await context.Topics.FindAsync(topicId);
     if (topic == null) return null;
     TopicViewModel vm = new TopicViewModel(req, topic.TopicTitle, topic.RawTextDescription,
         "/Pages/ContentUpload/TopicThumbnail?topicId=" + topicId);
     vm.HtmlDescription = topic.LongDescription;
     IOrderedQueryable<ArticleModel> newArticleQuery =
         context.Articles.Where(f => !f.IsDraft && f.ThemeId.Equals(topicId)).OrderBy(f => f.UpdateTime);
     List<CurrentRankingModel> rankingModel =
         context.CurrentRanking.Where(f => f.TopicId.Equals(topicId))
             .OrderBy(f => f.PVCoefficient).Take(20).ToList();
     var hotModels = rankingModel.Select(f => context.Articles.Find(f.ArticleId));
     vm.NewArticles = newArticleQuery;
     vm.HotModels = hotModels;
     vm.TopicId = topicId;
     return vm;
 }
Пример #6
0
 public static TenantContext <TTenant> GetTenantContext <TTenant>(this HttpRequestBase request)
 {
     Ensure.Argument.NotNull(request, "request");
     return(request.GetOwinContext().Environment.GetTenantContext <TTenant>());
 }
 private static IAuthenticationManager GetAuthManager(HttpRequestBase requestBase)
 {
     var ctx = requestBase.GetOwinContext();
     var authManager = ctx.Authentication;
     return authManager;
 }
 public IAuthenticationManager GetAuthManager(HttpRequestBase request)
 {
     var context = request.GetOwinContext();
     return context.Authentication;
 }
Пример #9
0
 public static MvcHtmlString GravatarImg(this HtmlHelper<dynamic> helper, HttpRequestBase req,int size=128)
 {
     var userManager = req.GetOwinContext().GetUserManager<ApplicationUserManager>();
     UserAccount user = userManager.FindByName(WebPageStatic.User().Identity.Name);
     if(user==null)return new MvcHtmlString("");
     BasicGravatarLoader loader=new BasicGravatarLoader(user.Email);
     return loader.GetIconTag(size);
 }