So I am trying to create a register page with my existing web API. There are a few post methods on the AccountController, but I have commented them all out apart from 2. Here is what they look like:
/// <summary>
/// Handles all account related functions.
/// </summary>
[Authorize]
[RoutePrefix("Account")]
public class AccountController : ApiController
{
private const string LocalLoginProvider = "Local";
private readonly IUnitOfWork unitOfWork;
private readonly UserService<User> service;
private readonly UserLoginService userLoginService;
private readonly RoleService<User> roleService;
private readonly ISecureDataFormat<AuthenticationTicket> accessTokenFormat;
/// <summary>
/// Parameterless Constructor which references the startup config auth options access token format.
/// </summary>
public AccountController()
: this(StartupConfig.OAuthOptions.AccessTokenFormat)
{
}
/// <summary>
/// Constructor with the access token format parameter.
/// </summary>
/// <param name="accessTokenFormat">The parameter for specifying the access token format.</param>
public AccountController(ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
{
this.unitOfWork = new UnitOfWork<DatabaseContext>();
this.service = new UserService<User>(this.unitOfWork, false, true);
this.userLoginService = new UserLoginService(this.unitOfWork);
this.roleService = new RoleService<User>(this.unitOfWork);
this.accessTokenFormat = accessTokenFormat;
}
// POST api/account/register
/// <summary>
/// Registers a new user with the system.
/// </summary>
/// <param name="model">The model representing the user.</param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
[Route("Register")]
[ResponseType(typeof(r3plica.Identity.IdentityResult))]
public async Task<IHttpActionResult> Register(RegisterBindingViewModel model)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
var user = new User
{
UserName = model.Email,
Email = model.Email
};
var result = await service.CreateAsync(user, model.Password);
var errorResult = GetErrorResult(result);
if (errorResult != null)
return errorResult;
await this.unitOfWork.SaveChangesAsync();
return Ok(user.Id);
}
// POST api/account/logout
/// <summary>
/// Logs the current user out.
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("Logout")]
public IHttpActionResult Logout()
{
Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
return Ok();
}
}
and my angular controller looks like this:
.controller('RegisterController', ['$state', 'Api', function ($state, api) {
var self = this;
self.model = {
email: '',
password: '',
confirmPassword: ''
};
self.register = function () {
api.post('account/register', self.model).then(function (response) {
console.log(response);
}, function (error) {
alert('error!');
});
};
}]);
If I comment out the Logout function in my AccountController, then try to register, it registers fine and all the fields are populated and correct. If I uncomment Logout and send the same form, I get an error:
Multiple actions were found that match the request:
Register on type AccountController
Logout on type AccountController
As you can see Logout is parameterless, so I am not sure why I am getting this error. Can someone tell me what I am doing wrong?