NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using Capstone_Project_WepApi.Model;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System.Text;
public class Startup
{

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

// Other configurations...
// Configure JWT authentication
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
};
});
// Other configurations...

}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Other configurations...
// Enable authentication middleware
app.UseAuthentication();
// Other configurations...
}
}

---model folder--
namespace Capstone_Project_WepApi.Model
{
public class cart
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public List<CartItem> CartItems { get; set; }

public cart()
{
CartItems = new List<CartItem>();
}

}
}
namespace Capstone_Project_WepApi.Model
{
public class CartItem
{
public Guid Id { get; set; }
public Guid ProductId { get; set; }
public int Quantity { get; set; }
}
}
namespace Capstone_Project_WepApi.Model
{
public class Payment
{
public Guid ProductId { get; set; }
public Guid UserId { get; set; }
public decimal Amount { get; set; }
public string PaymentMethod { get; set; }
// Add any other properties relevant to the payment
}
}namespace Capstone_Project_WepApi.Model
{
public class Product
{

public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
}
namespace Capstone_Project_WepApi.Model
{
public class User
{

public Guid Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }

}
}
using System.ComponentModel.DataAnnotations;

namespace Capstone_Project_WepApi.ViewModel
{
public class LoginViewModel
{
[Required]
public string Username { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
}
}
using System.ComponentModel.DataAnnotations;

namespace Capstone_Project_WepApi.ViewModel
{
public class RegisterViewModel
{
[Required]
public string Username { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
}
}

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Identity;
using System.Threading.Tasks;
using Capstone_Project_WepApi.Model;
using Capstone_Project_WepApi.ViewModel;
namespace YourProject.Controllers
{
[ApiController]
[Route("[controller]")]
public class AuthController : ControllerBase
{
private readonly UserManager<User> _userManager;
private readonly SignInManager<User> _signInManager;
public AuthController(UserManager<User> userManager, SignInManager<User> signInManager)
{
_userManager = userManager;
_signInManager = signInManager;
}
[HttpPost("register")]
public async Task<IActionResult> Register(RegisterViewModel model)
{
var user = new User { Username = model.Username };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
return Ok();
}
return BadRequest(result.Errors);
}
[HttpPost("login")]
public async Task<IActionResult> Login(LoginViewModel model)
{
var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, isPersistent: false, lockoutOnFailure: false);
if (result.Succeeded)
{
return Ok();
}
return BadRequest("Invalid username or password");
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.