Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "Hasan"

I think you did not understand the question I need another method like Authenticate in any Controller which should accept no input and but it has to be give me a Token

Is it possible in ASP.net ZERO ?

using System;
using System.Threading.Tasks;
using System.Web.Http;
using Abp.Authorization.Users;
using Abp.UI;
using Abp.Web.Models;
using Microsoft.Owin.Infrastructure;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.OAuth;
using DinePlan.DineConnect.Authorization;
using DinePlan.DineConnect.Authorization.Roles;
using DinePlan.DineConnect.Authorization.Users;
using DinePlan.DineConnect.MultiTenancy;
using DinePlan.DineConnect.WebApi.Models;

namespace DinePlan.DineConnect.WebApi.Controllers
{
    public class AccountController : DineConnectApiControllerBase
    {
        public static OAuthBearerAuthenticationOptions OAuthBearerOptions { get; private set; }

        private readonly UserManager _userManager;
        private readonly AbpLoginResultTypeHelper _abpLoginResultTypeHelper;

        static AccountController()
        {
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
        }

        public AccountController(
            UserManager userManager, 
            AbpLoginResultTypeHelper abpLoginResultTypeHelper)
        {
            _userManager = userManager;
            _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
        }

        [HttpPost]
        public async Task<AjaxResponse> Authenticate(LoginModel loginModel)
        {
            CheckModelState();

            var loginResult = await GetLoginResultAsync(
                loginModel.UsernameOrEmailAddress,
                loginModel.Password,
                loginModel.TenancyName
                );

            var ticket = new AuthenticationTicket(loginResult.Identity, new AuthenticationProperties());

            var currentUtc = new SystemClock().UtcNow;
            ticket.Properties.IssuedUtc = currentUtc;
            ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(30));

            return new AjaxResponse(OAuthBearerOptions.AccessTokenFormat.Protect(ticket));
        }


        private async Task<AbpUserManager<Tenant, Role, User>.AbpLoginResult> GetLoginResultAsync(string usernameOrEmailAddress, string password, string tenancyName)
        {
            var loginResult = await _userManager.LoginAsync(usernameOrEmailAddress, password, tenancyName);

            switch (loginResult.Result)
            {
                case AbpLoginResultType.Success:
                    return loginResult;
                default:
                    throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress, tenancyName);
            }
        }

        protected virtual void CheckModelState()
        {
            if (!ModelState.IsValid)
            {
                throw new UserFriendlyException("Invalid request!");
            }
        }
    }
}

Please execute this and let me know

Thanks

I have tried that and it is not working

Could you please check it ?

Please reply

I am waiting for the reply since last week

I will put it like this

I want to create one more method in the controller like

Account/Authenticate

How to achieve ?

Account/Authenticate does not expect Token.

Question

Hello Team,

I am building an Android App for my application on top of ASP.net ZERO

I am authenticating through

api/Account/Authenticate

Now, in My app i want to Send the Token automatically without sending Any Username and Password (for example, i want to have a TRY APP Feature )

How to build one ?

I have tried it but it is not allowing me to do that because it expects the Token in my request

Could you please let me know ?

Answer

How to Set it ?

Please show me a example

Thanks

Question

Hello Team

I would like to show the Menu based on the Feature.

How to achieve that ?

.AddItem(new MenuItemDefinition( PageNames.App.Tenant.Connect, L("Connect"), "fa fa-connectdevelop", requiredPermissionName: AppPermissions.Pages_Tenant_Connect )

Folks Any update ?

Question

Hello Team

Here is my question

In my application, I have a entity which stores Locations

Each Location will have one Organizational Unit and Organizational Unit have users

When the user logs in, I should be able to get all the location he is belongs to and I should restrict only the data relates to the Locations.

How to do that ?

Showing 61 to 70 of 97 entries