import { ExecutionContext } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
export class WsAuthGuard extends AuthGuard('wsjwt') {
constructor() {
super();
}
getRequest(context: ExecutionContext) {
return context.switchToWs().getClient().handshake;
}
}
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
@Injectable()
export class WsJwtStrategy extends PassportStrategy(Strategy, 'wsjwt') {
constructor(private readonly configService: ConfigService) {
super({
ignoreExpiration: false,
secretOrKey: configService.get('jwt.token.secret'),
jwtFromRequest: ExtractJwt.fromExtractors([
(request: Request) => {
const token = this.getTokenFromWebSocket(request.headers?.cookie);
return token;
},
]),
});
}
private getTokenFromWebSocket(cookie: string): string | null {
return this.getCookieValue(cookie, '_Secure-access-token');
}
private getCookieValue(cookieString: string, cookieName: string) {
const cookies = cookieString.split('; ');
for (const cookie of cookies) {
const [name, value] = cookie.split('=');
if (name === cookieName) {
return value;
}
}
return null;
}
async validate(payload: any) {
if (!payload) new UnauthorizedException();
return {
userId: payload.sub,
phone: payload.phone,
email: payload.email,
type: payload.type,
};
}
}
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFdAOCAQ8AMIIBCgKCAQEAv5yse9ka3ZQE0feuGtem
Yv3IqOlLck8zHUM7lTrdza6lXTszRSXfdO7jMb+L5C7e2QNFs+7sIX2OQJ6a+HG8
kr+jwJ4tS3c1sWtd9NXpsU40PE4MeNE5RqiNXjcDxA+L4OsEm/BlyFOEOh2epGyY
Ud5/iO3OiQFRNicomT2saQYAeqIwuELPs1XpLk9HLx5qPbm8fRrQhjeUD5TLO8b+
4yCnObe8vy/BMUwBfq+ieWADIjwWCMp2KTpMGLz48qnaD9kdrYJ0iyHqzb2mkDhd
Izkim24A3lWoYitJCBrrB2xM05sm9+OdCI1f7nPNJbl5URHobSwR94IRGT7CJcUj
vwIDAQAB
-----END PUBLIC KEY-----
const publicKey = fs.readFileSync('./rsaprivkey_public.key');
const encryptedData = crypto.publicEncrypt(
{
key: Buffer.from(publicKey),
padding: crypto.constants.RSA_PKCS1_PADDING,
},
Buffer.from(cardData),
);
public function update(Request $request, Language $localization)
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body));
$out = curl_exec($curl);
echo $out;
curl_close($curl);
}
$('.product-item .cart-btn').click(function(){
$(this).closest('.product-item').find('form.ms2_form').each(function(i, elem){
setTimeout(function(){
if ($(elem).find('input[name="count"]').val() > 0) {
//$(this).submit();
$(elem).find('.msmcd-action').click();
//$(this).find('.msmcd-action').trigger('click');
}
}, 1000 * i);
});
});